@@ -215,7 +215,11 @@ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
215215 if ( propertyDeclarationSyntax . Initializer != null )
216216 {
217217 var sm = context . Compilation . GetSemanticModel ( propertyDeclarationSyntax . Initializer . SyntaxTree ) ;
218- value = propertyDeclarationSyntax . Initializer . Value . FullQualifiedSyntax ( sm ) ;
218+ var initializerValue = propertyDeclarationSyntax . Initializer . Value ;
219+ if ( ! IsStaticallyResolvable ( initializerValue , sm ) )
220+ value = "default" ;
221+ else
222+ value = propertyDeclarationSyntax . Initializer . Value . FullQualifiedSyntax ( sm ) ;
219223 }
220224 else
221225 {
@@ -418,6 +422,106 @@ void AppendPartialContainingTypeDeclarations(INamedTypeSymbol? containingType)
418422 context . AddSource ( uniqueHint , SourceText . From ( source . ToString ( ) , Encoding . UTF8 ) ) ;
419423 }
420424
425+ private static bool IsStaticallyResolvable ( ExpressionSyntax expression , SemanticModel semanticModel )
426+ {
427+ // Handle literals (e.g., `10`, `"string"`, `true`, etc.)
428+ if ( expression is LiteralExpressionSyntax )
429+ {
430+ return true ;
431+ }
432+
433+ // Handle identifiers (e.g., variable names)
434+ if ( expression is IdentifierNameSyntax identifier )
435+ {
436+ var symbolInfo = semanticModel . GetSymbolInfo ( identifier ) . Symbol ;
437+
438+ // Ensure it's a static member
439+ return symbolInfo is { IsStatic : true } ;
440+ }
441+
442+ // Handle member access (e.g., `MyClass.StaticValue`)
443+ if ( expression is MemberAccessExpressionSyntax memberAccess )
444+ {
445+ var symbolInfo = semanticModel . GetSymbolInfo ( memberAccess ) . Symbol ;
446+
447+ // Ensure it's referring to a static member
448+ return symbolInfo is { IsStatic : true } ;
449+ }
450+
451+ // Handle object creation expressions (e.g., `new Vector2(1.0f, 2.0f)`)
452+ if ( expression is ObjectCreationExpressionSyntax objectCreation )
453+ {
454+ // Recursively ensure all its arguments are self-contained
455+ if ( objectCreation . ArgumentList == null )
456+ {
457+ return true ;
458+ }
459+ foreach ( var argument in objectCreation . ArgumentList . Arguments )
460+ {
461+ if ( ! IsStaticallyResolvable ( argument . Expression , semanticModel ) )
462+ {
463+ return false ;
464+ }
465+ }
466+
467+ return true ;
468+ }
469+
470+ if ( expression is ImplicitObjectCreationExpressionSyntax )
471+ {
472+ return true ;
473+ }
474+
475+ if ( expression is InvocationExpressionSyntax invocationExpression )
476+ {
477+ // Resolve the method being invoked
478+ var symbolInfo = semanticModel . GetSymbolInfo ( invocationExpression ) . Symbol ;
479+
480+ if ( symbolInfo is IMethodSymbol methodSymbol )
481+ {
482+ // Ensure the method is static
483+ if ( methodSymbol . IsStatic )
484+ {
485+ return true ;
486+ }
487+ }
488+ }
489+
490+ if ( expression is InterpolatedStringExpressionSyntax interpolatedString )
491+ {
492+ foreach ( var content in interpolatedString . Contents )
493+ {
494+ if ( content is not InterpolationSyntax interpolation )
495+ {
496+ continue ;
497+ }
498+ // Analyze the expression inside `${...}`
499+ var interpolatedExpression = interpolation . Expression ;
500+
501+ if ( ! IsStaticallyResolvable ( interpolatedExpression , semanticModel ) )
502+ {
503+ return false ;
504+ }
505+ }
506+ return true ;
507+ }
508+
509+ if ( expression is InitializerExpressionSyntax initializerExpressionSyntax )
510+ {
511+ foreach ( var content in initializerExpressionSyntax . Expressions )
512+ {
513+ if ( ! IsStaticallyResolvable ( content , semanticModel ) )
514+ {
515+ return false ;
516+ }
517+ }
518+ return true ;
519+ }
520+
521+ // Handle other expressions conservatively (e.g., method calls, instance references, etc.)
522+ return false ;
523+ }
524+
421525 private static bool MemberHasNodeType ( ITypeSymbol memberType , MarshalType marshalType )
422526 {
423527 if ( marshalType == MarshalType . GodotObjectOrDerived )
0 commit comments