@@ -370,22 +370,27 @@ Expr *sema_resolve_string_ident(SemaContext *context, Expr *inner, bool report_m
370370 return NULL ;
371371}
372372
373- Expr * sema_ct_eval_expr (SemaContext * context , CtEvalKind eval_kind , Expr * inner , bool report_missing )
373+ Expr * sema_ct_eval_expr (SemaContext * context , CtEvalKind eval_kind , Expr * inner , bool report_missing , bool * was_reflect )
374374{
375375 if (!sema_analyse_ct_expr (context , inner )) return NULL ;
376376 if (!expr_is_const_string (inner ))
377377 {
378+ if (was_reflect && inner -> resolve_status == RESOLVE_DONE && expr_is_const_reflection (inner ))
379+ {
380+ * was_reflect = true;
381+ return inner ;
382+ }
378383 switch (eval_kind )
379384 {
380385 case CT_EVAL_IDENTIFIER :
381386 RETURN_VAL_SEMA_ERROR (poisoned_expr , inner , "'$eval' expects a constant string as the argument." );
382387 case CT_EVAL_IMPLICIT_IDENTIFIER :
383- if (inner -> resolve_status == RESOLVE_DONE && expr_is_const_reflection (inner )) return inner ;
384388 RETURN_VAL_SEMA_ERROR (poisoned_expr , inner , "A constant string was expected as the argument." );
385389 default :
386390 UNREACHABLE
387391 }
388392 }
393+ if (was_reflect ) * was_reflect = false;
389394 return sema_resolve_string_ident (context , inner , report_missing );
390395}
391396
@@ -3646,7 +3651,7 @@ INLINE bool sema_expr_analyse_lookup(SemaContext *context, Expr *expr, Expr *tag
36463651 if (!sema_analyse_expr_rvalue (context , key )) return false;
36473652 ArrayIndex index ;
36483653
3649- Expr * ident = sema_expr_resolve_access_child (context , args [0 ], NULL , false );
3654+ Expr * ident = sema_expr_resolve_access_child (context , args [0 ], NULL , NULL );
36503655 if (!ident ) return false;
36513656 if (ident -> expr_kind != EXPR_UNRESOLVED_IDENTIFIER ) RETURN_SEMA_ERROR (expr , "This is not a field." );
36523657 const char * child = ident -> unresolved_ident_expr .ident ;
@@ -4987,7 +4992,7 @@ static inline bool sema_expr_analyse_slice(SemaContext *context, Expr *expr)
49874992 * 5. .$ident -> resolve as `$eval($ident)`
49884993 * 6. .$Type -> It is a child to resolve as CT type param
49894994 */
4990- Expr * sema_expr_resolve_access_child (SemaContext * context , Expr * child , bool * missing , bool allow_reflect )
4995+ Expr * sema_expr_resolve_access_child (SemaContext * context , Expr * child , bool * missing , bool * was_reflect )
49914996{
49924997 SourceLocId loc = child -> loc ;
49934998 bool in_hash = false;
@@ -5009,15 +5014,15 @@ static inline bool sema_expr_analyse_slice(SemaContext *context, Expr *expr)
50095014 return child ;
50105015 case EXPR_CT_IDENT :
50115016 {
5012- Expr * result = sema_ct_eval_expr (context , CT_EVAL_IMPLICIT_IDENTIFIER , child , missing == NULL );
5017+ Expr * result = sema_ct_eval_expr (context , CT_EVAL_IMPLICIT_IDENTIFIER , child , missing == NULL , was_reflect );
50135018 if (!expr_ok (result )) return NULL ;
50145019 if (!result )
50155020 {
50165021 if (missing ) * missing = true;
50175022 return NULL ;
50185023 }
50195024 expr_replace (child , result );
5020- if (result -> resolve_status == RESOLVE_DONE && expr_is_const_reflection ( result ) ) return child ;
5025+ if (was_reflect && * was_reflect ) return child ;
50215026 goto RETRY ;
50225027 }
50235028 case EXPR_TYPEINFO :
@@ -5027,14 +5032,15 @@ static inline bool sema_expr_analyse_slice(SemaContext *context, Expr *expr)
50275032 {
50285033 ASSERT_SPAN (child , child -> resolve_status != RESOLVE_DONE );
50295034 // Only report missing if missing var is NULL
5030- Expr * result = sema_ct_eval_expr (context , CT_EVAL_IDENTIFIER , child -> inner_expr , missing == NULL );
5035+ Expr * result = sema_ct_eval_expr (context , CT_EVAL_IDENTIFIER , child -> inner_expr , missing == NULL , was_reflect );
50315036 if (!expr_ok (result )) return NULL ;
50325037 if (!result )
50335038 {
50345039 if (missing ) * missing = true;
50355040 return NULL ;
50365041 }
50375042 expr_replace (child , result );
5043+ if (was_reflect && * was_reflect ) return child ;
50385044 goto RETRY ;
50395045 }
50405046 default :
@@ -6718,15 +6724,16 @@ static inline bool sema_expr_analyse_access(SemaContext *context, Expr *expr, bo
67186724 if (child -> expr_kind == EXPR_TYPEINFO ) RETURN_SEMA_ERROR (child , "A type can't appear here." );
67196725
67206726 // 3. Find the actual token.
6721- Expr * identifier = sema_expr_resolve_access_child (context , child , missing_ref , true);
6727+ bool is_reflect = false;
6728+ Expr * identifier = sema_expr_resolve_access_child (context , child , missing_ref , & is_reflect );
67226729 if (!identifier ) return false;
67236730 Decl * member ;
67246731 Decl * decl ;
67256732 Expr * current_parent ;
67266733 bool optional ;
67276734 const char * kw ;
67286735 Type * underlying_type ;
6729- if (identifier -> resolve_status == RESOLVE_DONE && expr_is_const_reflection ( identifier ) )
6736+ if (is_reflect )
67306737 {
67316738 Expr * reflect = identifier -> const_expr .reflection ;
67326739 if (!expr_is_const_member (reflect )) RETURN_SEMA_ERROR (identifier , "Expected a member reference." );
@@ -10717,7 +10724,7 @@ static inline bool sema_expr_analyse_decl_element(SemaContext *context, Designat
1071710724 * member_ref = NULL ;
1071810725 return true;
1071910726 }
10720- Expr * field = sema_expr_resolve_access_child (context , element -> field_expr , is_missing , false );
10727+ Expr * field = sema_expr_resolve_access_child (context , element -> field_expr , is_missing , NULL );
1072110728 if (!field ) return false;
1072210729 if (field -> expr_kind != EXPR_UNRESOLVED_IDENTIFIER ) RETURN_SEMA_ERROR (field , "Expected an identifier here." );
1072310730 const char * kw = field -> unresolved_ident_expr .ident ;
@@ -11480,7 +11487,7 @@ static inline bool sema_expr_analyse_ct_defined(SemaContext *context, Expr *expr
1148011487 }
1148111488 case EXPR_CT_EVAL :
1148211489 {
11483- Expr * eval = sema_ct_eval_expr (active_context , CT_EVAL_IDENTIFIER , main_expr -> inner_expr , false);
11490+ Expr * eval = sema_ct_eval_expr (active_context , CT_EVAL_IDENTIFIER , main_expr -> inner_expr , false, NULL );
1148411491 if (!expr_ok (eval )) return false;
1148511492 if (eval )
1148611493 {
@@ -11785,7 +11792,7 @@ static inline bool sema_expr_analyse_ct_stringify(SemaContext *context, Expr *ex
1178511792
1178611793static inline bool sema_expr_resolve_ct_eval (SemaContext * context , Expr * expr )
1178711794{
11788- Expr * result = sema_ct_eval_expr (context , CT_EVAL_IDENTIFIER , expr -> inner_expr , true);
11795+ Expr * result = sema_ct_eval_expr (context , CT_EVAL_IDENTIFIER , expr -> inner_expr , true, NULL );
1178911796 if (!result ) return false;
1179011797 if (result -> expr_kind == EXPR_TYPEINFO )
1179111798 {
0 commit comments