@@ -2830,8 +2830,8 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) Error
28302830 defer analyser .arena .free (lineage );
28312831
28322832 const tag = offsets .identifierTokenToNameSlice (tree , tree .nodeMainToken (node ));
2833- const decl = (try analyser .lookupSymbolFieldInit (handle , tag , node , lineage [1.. ])) orelse return Type .fromIP (analyser , .enum_literal_type , null );
2834- return decl .resolveType (analyser );
2833+ const decl , const type_maybe = (try analyser .lookupSymbolFieldInit (handle , tag , node , lineage [1.. ])) orelse return Type .fromIP (analyser , .enum_literal_type , null );
2834+ return type_maybe orelse decl .resolveType (analyser );
28352835 },
28362836
28372837 .unreachable_literal = > return Type .fromIP (analyser , .noreturn_type , null ),
@@ -6338,7 +6338,7 @@ pub fn lookupSymbolFieldInit(
63386338 field_name : []const u8 ,
63396339 node : Ast.Node.Index ,
63406340 ancestors : []const Ast.Node.Index ,
6341- ) Error ! ? DeclWithHandle {
6341+ ) Error ! ? struct { DeclWithHandle , ? Type } {
63426342 var container_type = (try analyser .resolveExpressionType (
63436343 handle ,
63446344 node ,
@@ -6365,13 +6365,22 @@ pub fn lookupSymbolFieldInit(
63656365 container_type = try container_type .instanceUnchecked (analyser );
63666366
63676367 if (is_struct_init ) {
6368- return try container_type .lookupSymbol (analyser , field_name );
6368+ const decl = try container_type .lookupSymbol (analyser , field_name ) orelse return null ;
6369+ return .{ decl , null };
6370+ }
6371+
6372+ switch (container_type .data ) {
6373+ .union_tag = > | t | {
6374+ const decl = try t .lookupSymbol (analyser , field_name ) orelse return null ;
6375+ return .{ decl , container_type };
6376+ },
6377+ else = > {},
63696378 }
63706379
63716380 switch (container_type .getContainerKind () orelse return null ) {
63726381 .keyword_struct , .keyword_opaque = > {},
6373- .keyword_enum = > if (try (try container_type .typeOf (analyser )).lookupSymbol (analyser , field_name )) | ty | return ty ,
6374- .keyword_union = > if (try container_type .lookupSymbol (analyser , field_name )) | ty | return ty ,
6382+ .keyword_enum = > if (try (try container_type .typeOf (analyser )).lookupSymbol (analyser , field_name )) | decl | return .{ decl , null } ,
6383+ .keyword_union = > if (try container_type .lookupSymbol (analyser , field_name )) | decl | return .{ decl , null } ,
63756384 else = > return null ,
63766385 }
63776386
@@ -6382,7 +6391,7 @@ pub fn lookupSymbolFieldInit(
63826391 resolved_type = try resolved_type .typeOf (analyser );
63836392 resolved_type = resolved_type .resolveDeclLiteralResultType ();
63846393 resolved_type = try resolved_type .instanceUnchecked (analyser );
6385- if (resolved_type .eql (container_type )) return decl ;
6394+ if (resolved_type .eql (container_type )) return .{ decl , null } ;
63866395 return null ;
63876396}
63886397
@@ -6425,8 +6434,9 @@ pub fn resolveExpressionTypeFromAncestors(
64256434 const field_name_token = tree .firstToken (node ) - 2 ;
64266435 if (tree .tokenTag (field_name_token ) != .identifier ) return null ;
64276436 const field_name = offsets .identifierTokenToNameSlice (tree , field_name_token );
6428- if (try analyser .lookupSymbolFieldInit (handle , field_name , ancestors [0 ], ancestors [1.. ])) | field_decl | {
6429- return try field_decl .resolveType (analyser );
6437+ if (try analyser .lookupSymbolFieldInit (handle , field_name , ancestors [0 ], ancestors [1.. ])) | field | {
6438+ const decl , const type_maybe = field ;
6439+ return type_maybe orelse try decl .resolveType (analyser );
64306440 }
64316441 }
64326442 },
@@ -6568,8 +6578,8 @@ pub fn resolveExpressionTypeFromAncestors(
65686578
65696579 var fn_type = if (tree .nodeTag (call .ast .fn_expr ) == .enum_literal ) blk : {
65706580 const field_name = offsets .identifierTokenToNameSlice (tree , tree .nodeMainToken (call .ast .fn_expr ));
6571- const decl = try analyser .lookupSymbolFieldInit (handle , field_name , call .ast .fn_expr , ancestors ) orelse return null ;
6572- const ty = try decl .resolveType (analyser ) orelse return null ;
6581+ const decl , const type_maybe = try analyser .lookupSymbolFieldInit (handle , field_name , call .ast .fn_expr , ancestors ) orelse return null ;
6582+ const ty = type_maybe orelse try decl .resolveType (analyser ) orelse return null ;
65736583 break :blk try analyser .resolveFuncProtoOfCallable (ty ) orelse return null ;
65746584 } else blk : {
65756585 const ty = try analyser .resolveTypeOfNode (.of (call .ast .fn_expr , handle )) orelse return null ;
@@ -6829,7 +6839,7 @@ pub fn getSymbolEnumLiteral(
68296839 handle : * DocumentStore.Handle ,
68306840 source_index : usize ,
68316841 name : []const u8 ,
6832- ) Error ! ? DeclWithHandle {
6842+ ) Error ! ? struct { DeclWithHandle , ? Type } {
68336843 const tracy_zone = tracy .trace (@src ());
68346844 defer tracy_zone .end ();
68356845
0 commit comments