|
@@ -444,6 +444,32 @@ Type TValDecl Extends TDecl
|
|
|
End If
|
|
|
|
|
|
init=declInit.Copy().SemantAndCast(ty)
|
|
|
+
|
|
|
+ ' check if struct has been initialised
|
|
|
+ If TObjectType(ty) And TObjectType(ty).classDecl.IsStruct() Then
|
|
|
+
|
|
|
+ ' new not used
|
|
|
+ If TConstExpr(init) And Not TConstExpr(init).value Then
|
|
|
+
|
|
|
+ Local found:Int = False
|
|
|
+ ' struct contains any objects?
|
|
|
+ For Local fld:TFieldDecl = EachIn TObjectType(ty).classDecl._decls
|
|
|
+ If Not fld.IsSemanted() Then
|
|
|
+ fld.Semant()
|
|
|
+ End If
|
|
|
+
|
|
|
+ If TObjectType(fld.ty) Or TStringType(fld.ty) Or TArrayType(fld.ty) Then
|
|
|
+ found = True
|
|
|
+ Exit
|
|
|
+ End If
|
|
|
+ Next
|
|
|
+
|
|
|
+ ' we need to initialise object fields, so we'll call the default constructor
|
|
|
+ If found Then
|
|
|
+ init = New TNewObjectExpr.Create(ty, Null).Semant()
|
|
|
+ End If
|
|
|
+ End If
|
|
|
+ End If
|
|
|
End If
|
|
|
End If
|
|
|
Else If declInit
|