Browse Source

Fixed comptime valueless ctor

Brian Fiete 3 năm trước cách đây
mục cha
commit
b5ddc1c24b
2 tập tin đã thay đổi với 11 bổ sung5 xóa
  1. 5 5
      IDEHelper/Compiler/CeMachine.cpp
  2. 6 0
      IDEHelper/Tests/src/ConstEval.bf

+ 5 - 5
IDEHelper/Compiler/CeMachine.cpp

@@ -5149,14 +5149,14 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod
 				Fail("Failed to encode return argument");
 			}
 		}
-		else if (returnType->IsComposite())
+		else if ((methodInstance->mMethodDef->mMethodType == BfMethodType_Ctor) && (thisType != NULL) && (thisType->IsValuelessType()))
 		{
-			returnValue = BfTypedValue(module->mBfIRBuilder->CreateConstAggZero(module->mBfIRBuilder->MapType(returnType, BfIRPopulateType_Identity)), returnType);
+			returnValue = BfTypedValue(module->mBfIRBuilder->CreateConstAggZero(module->mBfIRBuilder->MapType(returnType, BfIRPopulateType_Identity)), thisType);
 		}
-		else if (returnType->IsValuelessType())
+		else if ((returnType->IsComposite()) || (returnType->IsValuelessType()))
 		{
-			returnValue = BfTypedValue(module->mBfIRBuilder->GetFakeVal(), returnType);			
-		}
+			returnValue = BfTypedValue(module->mBfIRBuilder->CreateConstAggZero(module->mBfIRBuilder->MapType(returnType, BfIRPopulateType_Identity)), returnType);
+		}		
 	}
 
 	mCallStack.Clear();

+ 6 - 0
IDEHelper/Tests/src/ConstEval.bf

@@ -32,6 +32,12 @@ namespace Tests
 			}
 		}
 
+		struct ZeroStruct
+		{
+			public this() { }
+			public const ZeroStruct ConstValue = ZeroStruct();
+		}
+
 		const String cStrA = "Abc";
 		const String cStrB = GetStringA(cStrA, 12, 23);