lang: qualified namespace members in value position + alias carry
Two coupled capabilities on the road to the std restructure (current/PLAN-STDLIB.md, issue 0114): 1. alias.Type.method() / alias.Type as a call head, alias.CONST, and alias.Enum.variant now resolve — previously only alias.fn() and type-position alias.Type worked. objectIsValue treats an alias-rooted field_access as a type head; the call path strips the alias to the existing Type.method machinery; lowerFieldAccess resolves alias.CONST pinned to the target module and alias.Enum.x as a typed enum literal; resolveTypeWithBindings resolves qualified type_exprs pinned to the target. 2. The carry rule: namespaceAliasTarget resolves an alias from the file's own edges first, then from DIRECT flat imports (one level), diagnosing two distinct carried targets as ambiguous. All qualified shapes work through a carried alias — the std.sx namespace tail (mem.GPA.init() etc.) is now expressible. Regression: examples/0831-modules-namespace-alias-carry.sx (direct + carried, all seven shapes).
This commit is contained in:
20
examples/0831-modules-namespace-alias-carry.sx
Normal file
20
examples/0831-modules-namespace-alias-carry.sx
Normal file
@@ -0,0 +1,20 @@
|
||||
// Namespace aliases are module surface: a `ns :: #import` declared by a
|
||||
// module is usable by that module's DIRECT flat importers (the carry rule —
|
||||
// no `pub` keyword). Covers every qualified shape through BOTH a direct and
|
||||
// a carried alias: plain fn, struct static method + instance method, type
|
||||
// annotation, enum variant, module const, generic struct.
|
||||
|
||||
#import "modules/std.sx";
|
||||
#import "0831-modules-namespace-alias-carry/facade.sx";
|
||||
|
||||
main :: () {
|
||||
print("{} ", r.helper()); // plain fn (carried)
|
||||
t := r.Thing.init(); // static method
|
||||
print("{} ", t.get());
|
||||
x : r.Thing = r.Thing.init(); // type annotation
|
||||
print("{} ", x.v);
|
||||
print("{} ", r.LIMIT); // module const
|
||||
print("{} ", r.Color.green); // enum variant
|
||||
b := r.Box(s64).{ item = 3 }; // generic struct
|
||||
print("{}\n", b.item);
|
||||
}
|
||||
1
examples/0831-modules-namespace-alias-carry/facade.sx
Normal file
1
examples/0831-modules-namespace-alias-carry/facade.sx
Normal file
@@ -0,0 +1 @@
|
||||
r :: #import "rich.sx";
|
||||
9
examples/0831-modules-namespace-alias-carry/rich.sx
Normal file
9
examples/0831-modules-namespace-alias-carry/rich.sx
Normal file
@@ -0,0 +1,9 @@
|
||||
Thing :: struct {
|
||||
v: s64;
|
||||
init :: () -> Thing { Thing.{ v = 5 } }
|
||||
get :: (self: *Thing) -> s64 { self.v }
|
||||
}
|
||||
Color :: enum { red; green; }
|
||||
LIMIT :s64: 99;
|
||||
Box :: struct ($T: Type) { item: T; }
|
||||
helper :: () -> s64 { 7 }
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
7 5 5 99 .green 3
|
||||
Reference in New Issue
Block a user