summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2025-01-29 12:13:13 -0600
committerGitHub <noreply@github.com>2025-01-29 10:13:13 -0800
commit605204374658fc6d7f647f9a57e9e322b8c83100 (patch)
treeb66d71c5fcb0aad275553a8a63b2425ca10593ab /source
parentc18c4365af77fde279abed33876388961a180b3d (diff)
Fix the type coerce issue (#6215)
* Fix the type coerce issue When synthesize the default ctor, if there is a base type we will synthesize an InvokeExpr to call base type's default ctor as well. But we should use the type of the inheritanceDecl instead of base struct decl.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check-decl.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index d0c3e8d96..d12374d52 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -324,13 +324,17 @@ struct SemanticsDeclBodyVisitor : public SemanticsDeclVisitorBase,
StructDecl* parent = nullptr;
ConstructorDecl* defaultCtor = nullptr;
List<ConstructorDecl*> ctorList;
+ Type* type = nullptr;
DeclAndCtorInfo() {}
DeclAndCtorInfo(
ASTBuilder* m_astBuilder,
SemanticsVisitor* visitor,
- StructDecl* parent,
+ StructDecl* inParent,
+ Type* inType,
const bool getOnlyDefault)
{
+ parent = inParent;
+ type = inType;
if (getOnlyDefault)
defaultCtor = _getDefaultCtor(parent);
else
@@ -9073,19 +9077,22 @@ void SemanticsDeclBodyVisitor::synthesizeCtorBodyForBases(
if (!declInfo.defaultCtor)
continue;
+ auto declRefType = as<DeclRefType>(declInfo.type);
+
auto ctorToInvoke = m_astBuilder->create<VarExpr>();
- ctorToInvoke->declRef = declInfo.defaultCtor->getDefaultDeclRef();
+ ctorToInvoke->declRef = declRefType->getDeclRef();
ctorToInvoke->name = declInfo.defaultCtor->getName();
ctorToInvoke->loc = declInfo.defaultCtor->loc;
- ctorToInvoke->type = m_astBuilder->getFuncType(ArrayView<Type*>(), ctor->returnType.type);
+ ctorToInvoke->type = m_astBuilder->getFuncType(ArrayView<Type*>(), declRefType);
auto invoke = m_astBuilder->create<InvokeExpr>();
invoke->functionExpr = ctorToInvoke;
auto assign = m_astBuilder->create<AssignExpr>();
- assign->left =
- coerce(CoercionSite::Initializer, declInfo.defaultCtor->returnType.type, thisExpr);
+
+ assign->left = coerce(CoercionSite::Initializer, declRefType, thisExpr);
assign->right = invoke;
+
auto stmt = m_astBuilder->create<ExpressionStmt>();
stmt->expression = assign;
stmt->loc = ctor->loc;
@@ -9195,9 +9202,14 @@ void SemanticsDeclBodyVisitor::visitAggTypeDecl(AggTypeDecl* aggTypeDecl)
if (!structOfInheritance)
continue;
inheritanceDefaultCtorList.add(
- DeclAndCtorInfo(m_astBuilder, this, structOfInheritance, true));
+ DeclAndCtorInfo(m_astBuilder, this, structOfInheritance, declRefType, true));
}
- DeclAndCtorInfo structDeclInfo = DeclAndCtorInfo(m_astBuilder, this, structDecl, false);
+ DeclAndCtorInfo structDeclInfo = DeclAndCtorInfo(
+ m_astBuilder,
+ this,
+ structDecl,
+ calcThisType(makeDeclRef(structDecl)),
+ false);
// ensure all varDecl members are processed up to SemanticsBodyVisitor so we can be sure that if
// init expressions of members are to be synthisised, they are.