فهرست منبع

Fixed struct initialiser. Fixes #266.

woollybah 8 سال پیش
والد
کامیت
902008f68e
1فایلهای تغییر یافته به همراه26 افزوده شده و 0 حذف شده
  1. 26 0
      decl.bmx

+ 26 - 0
decl.bmx

@@ -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