@@ -2013,7 +2013,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn
2013
2013
},
2014
2014
.local_val = > scope = scope .cast (Scope .LocalVal ).? .parent ,
2015
2015
.local_ptr = > scope = scope .cast (Scope .LocalPtr ).? .parent ,
2016
- .namespace = > break ,
2016
+ .namespace , .enum_namespace = > break ,
2017
2017
.defer_normal , .defer_error = > scope = scope .cast (Scope .Defer ).? .parent ,
2018
2018
.top = > unreachable ,
2019
2019
}
@@ -2088,7 +2088,7 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index)
2088
2088
try parent_gz .addDefer (defer_scope .index , defer_scope .len );
2089
2089
},
2090
2090
.defer_error = > scope = scope .cast (Scope .Defer ).? .parent ,
2091
- .namespace = > break ,
2091
+ .namespace , .enum_namespace = > break ,
2092
2092
.top = > unreachable ,
2093
2093
}
2094
2094
}
@@ -2179,7 +2179,7 @@ fn checkLabelRedefinition(astgen: *AstGen, parent_scope: *Scope, label: Ast.Toke
2179
2179
.local_val = > scope = scope .cast (Scope .LocalVal ).? .parent ,
2180
2180
.local_ptr = > scope = scope .cast (Scope .LocalPtr ).? .parent ,
2181
2181
.defer_normal , .defer_error = > scope = scope .cast (Scope .Defer ).? .parent ,
2182
- .namespace = > break ,
2182
+ .namespace , .enum_namespace = > break ,
2183
2183
.top = > unreachable ,
2184
2184
}
2185
2185
}
@@ -2729,7 +2729,7 @@ fn countDefers(outer_scope: *Scope, inner_scope: *Scope) struct {
2729
2729
const have_err_payload = defer_scope .remapped_err_code != 0 ;
2730
2730
need_err_code = need_err_code or have_err_payload ;
2731
2731
},
2732
- .namespace = > unreachable ,
2732
+ .namespace , .enum_namespace = > unreachable ,
2733
2733
.top = > unreachable ,
2734
2734
}
2735
2735
}
@@ -2799,7 +2799,7 @@ fn genDefers(
2799
2799
.normal_only = > continue ,
2800
2800
}
2801
2801
},
2802
- .namespace = > unreachable ,
2802
+ .namespace , .enum_namespace = > unreachable ,
2803
2803
.top = > unreachable ,
2804
2804
}
2805
2805
}
@@ -2835,7 +2835,7 @@ fn checkUsed(gz: *GenZir, outer_scope: *Scope, inner_scope: *Scope) InnerError!v
2835
2835
scope = s .parent ;
2836
2836
},
2837
2837
.defer_normal , .defer_error = > scope = scope .cast (Scope .Defer ).? .parent ,
2838
- .namespace = > unreachable ,
2838
+ .namespace , .enum_namespace = > unreachable ,
2839
2839
.top = > unreachable ,
2840
2840
}
2841
2841
}
@@ -4278,7 +4278,7 @@ fn testDecl(
4278
4278
.local_val , .local_ptr = > unreachable , // a test cannot be in a local scope
4279
4279
.gen_zir = > s = s .cast (GenZir ).? .parent ,
4280
4280
.defer_normal , .defer_error = > s = s .cast (Scope .Defer ).? .parent ,
4281
- .namespace = > {
4281
+ .namespace , .enum_namespace = > {
4282
4282
const ns = s .cast (Scope .Namespace ).? ;
4283
4283
if (ns .decls .get (name_str_index )) | i | {
4284
4284
if (found_already ) | f | {
@@ -4963,6 +4963,7 @@ fn containerDecl(
4963
4963
defer block_scope .unstack ();
4964
4964
4965
4965
_ = try astgen .scanDecls (& namespace , container_decl .ast .members );
4966
+ namespace .base .tag = .enum_namespace ;
4966
4967
4967
4968
const arg_inst : Zir.Inst.Ref = if (container_decl .ast .arg != 0 )
4968
4969
try comptimeExpr (& block_scope , & namespace .base , .{ .rl = .{ .ty = .type_type } }, container_decl .ast .arg )
@@ -4977,6 +4978,7 @@ fn containerDecl(
4977
4978
for (container_decl .ast .members ) | member_node | {
4978
4979
if (member_node == counts .nonexhaustive_node )
4979
4980
continue ;
4981
+ namespace .base .tag = .namespace ;
4980
4982
var member = switch (try containerMember (& block_scope , & namespace .base , & wip_members , member_node )) {
4981
4983
.decl = > continue ,
4982
4984
.field = > | field | field ,
@@ -5010,6 +5012,7 @@ fn containerDecl(
5010
5012
},
5011
5013
);
5012
5014
}
5015
+ namespace .base .tag = .enum_namespace ;
5013
5016
const tag_value_inst = try expr (& block_scope , & namespace .base , .{ .rl = .{ .ty = arg_inst } }, member .ast .value_expr );
5014
5017
wip_members .appendToField (@enumToInt (tag_value_inst ));
5015
5018
}
@@ -7296,7 +7299,7 @@ fn localVarRef(
7296
7299
},
7297
7300
.gen_zir = > s = s .cast (GenZir ).? .parent ,
7298
7301
.defer_normal , .defer_error = > s = s .cast (Scope .Defer ).? .parent ,
7299
- .namespace = > {
7302
+ .namespace , .enum_namespace = > {
7300
7303
const ns = s .cast (Scope .Namespace ).? ;
7301
7304
if (ns .decls .get (name_str_index )) | i | {
7302
7305
if (found_already ) | f | {
@@ -7308,7 +7311,7 @@ fn localVarRef(
7308
7311
// We found a match but must continue looking for ambiguous references to decls.
7309
7312
found_already = i ;
7310
7313
}
7311
- num_namespaces_out += 1 ;
7314
+ if ( s . tag == .namespace ) num_namespaces_out += 1 ;
7312
7315
capturing_namespace = ns ;
7313
7316
s = ns .parent ;
7314
7317
},
@@ -7935,7 +7938,7 @@ fn builtinCall(
7935
7938
},
7936
7939
.gen_zir = > s = s .cast (GenZir ).? .parent ,
7937
7940
.defer_normal , .defer_error = > s = s .cast (Scope .Defer ).? .parent ,
7938
- .namespace = > {
7941
+ .namespace , .enum_namespace = > {
7939
7942
const ns = s .cast (Scope .Namespace ).? ;
7940
7943
if (ns .decls .get (decl_name )) | i | {
7941
7944
if (found_already ) | f | {
@@ -10547,6 +10550,12 @@ const Scope = struct {
10547
10550
else = > return null ,
10548
10551
}
10549
10552
}
10553
+ if (T == Namespace ) {
10554
+ switch (base .tag ) {
10555
+ .namespace , .enum_namespace = > return @fieldParentPtr (T , "base" , base ),
10556
+ else = > return null ,
10557
+ }
10558
+ }
10550
10559
if (base .tag != T .base_tag )
10551
10560
return null ;
10552
10561
@@ -10559,7 +10568,7 @@ const Scope = struct {
10559
10568
.local_val = > base .cast (LocalVal ).? .parent ,
10560
10569
.local_ptr = > base .cast (LocalPtr ).? .parent ,
10561
10570
.defer_normal , .defer_error = > base .cast (Defer ).? .parent ,
10562
- .namespace = > base .cast (Namespace ).? .parent ,
10571
+ .namespace , .enum_namespace = > base .cast (Namespace ).? .parent ,
10563
10572
.top = > null ,
10564
10573
};
10565
10574
}
@@ -10571,6 +10580,7 @@ const Scope = struct {
10571
10580
defer_normal ,
10572
10581
defer_error ,
10573
10582
namespace ,
10583
+ enum_namespace ,
10574
10584
top ,
10575
10585
};
10576
10586
@@ -12247,7 +12257,7 @@ fn detectLocalShadowing(
12247
12257
}
12248
12258
s = local_ptr .parent ;
12249
12259
},
12250
- .namespace = > {
12260
+ .namespace , .enum_namespace = > {
12251
12261
outer_scope = true ;
12252
12262
const ns = s .cast (Scope .Namespace ).? ;
12253
12263
const decl_node = ns .decls .get (ident_name ) orelse {
@@ -12415,7 +12425,7 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const Ast.
12415
12425
}
12416
12426
s = local_ptr .parent ;
12417
12427
},
12418
- .namespace = > s = s .cast (Scope .Namespace ).? .parent ,
12428
+ .namespace , .enum_namespace = > s = s .cast (Scope .Namespace ).? .parent ,
12419
12429
.gen_zir = > s = s .cast (GenZir ).? .parent ,
12420
12430
.defer_normal , .defer_error = > s = s .cast (Scope .Defer ).? .parent ,
12421
12431
.top = > break ,
0 commit comments