Skip to content

Commit

Permalink
fix bug: default value of parameter
Browse files Browse the repository at this point in the history
We should not use parameter's default value in the synthesized
member-init ctor. The default value should only be used when
call site doesn't provide enough arguments, and our invoke system
will use those default value to make up the missing arguments.

Add '-vk' to few tests to enable vulkan backend test.
  • Loading branch information
kaizhangNV committed Jan 13, 2025
1 parent ed51fa1 commit 093bf71
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
23 changes: 8 additions & 15 deletions source/slang/slang-check-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9180,20 +9180,13 @@ Expr* SemanticsDeclBodyVisitor::createCtorParamExpr(ConstructorDecl* ctor, Index
{
if (auto param = as<ParamDecl>(ctor->members[paramIndex]))
{
if (param->initExpr)
{
return param->initExpr;
}
else
{
auto paramType = param->getType();
auto paramExpr = m_astBuilder->create<VarExpr>();
paramExpr->scope = ctor->ownedScope;
paramExpr->declRef = param;
paramExpr->type = paramType;
paramExpr->loc = param->loc;
return paramExpr;
}
auto paramType = param->getType();
auto paramExpr = m_astBuilder->create<VarExpr>();
paramExpr->scope = ctor->ownedScope;
paramExpr->declRef = param;
paramExpr->type = paramType;
paramExpr->loc = param->loc;
return paramExpr;
}
}
return nullptr;
Expand Down Expand Up @@ -9255,7 +9248,7 @@ void SemanticsDeclBodyVisitor::synthesizeCtorBodyForBases(

auto assign = m_astBuilder->create<AssignExpr>();
assign->left =
coerce(CoercionSite::Initializer, declInfo.defaultCtor->returnType.type, thisExpr);
coerce(CoercionSite::Initializer, baseCtor->returnType.type, thisExpr);
assign->right = invoke;

auto stmt = m_astBuilder->create<ExpressionStmt>();
Expand Down
1 change: 1 addition & 0 deletions tests/compute/struct-default-init.slang
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// struct-default-init.slang
//TEST(compute):COMPARE_COMPUTE: -shaderobj
//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj

struct Test
{
Expand Down
8 changes: 4 additions & 4 deletions tests/diagnostics/mismatching-types.slang.expected
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ tests/diagnostics/mismatching-types.slang(61): error 30019: expected an expressi
tests/diagnostics/mismatching-types.slang(63): error 30019: expected an expression of type 'GenericOuter<int>.NonGenericInner', got 'GenericOuter<float>.NonGenericInner'
a.ng = b.ng;
^~
tests/diagnostics/mismatching-types.slang(66): error 30019: expected an expression of type 'GenericInner<int>', got 'int'
tests/diagnostics/mismatching-types.slang(66): error 30019: expected an expression of type 'NonGenericOuter.GenericInner<int>', got 'int'
c.i = 0;
^
tests/diagnostics/mismatching-types.slang(68): note: explicit conversion from 'int' to 'GenericInner<int>' is possible
tests/diagnostics/mismatching-types.slang(68): error 30019: expected an expression of type 'NonGenericOuter.GenericInner<int>', got 'NonGenericOuter.GenericInner<float>'
c.i = c.f;
^
tests/diagnostics/mismatching-types.slang(72): error 30019: expected an expression of type 'GenericInner<int>.ReallyNested', got 'int'
tests/diagnostics/mismatching-types.slang(72): error 30019: expected an expression of type 'NonGenericOuter.GenericInner<int>.ReallyNested', got 'int'
c.i.n = 0;
^
tests/diagnostics/mismatching-types.slang(72): note: explicit conversion from 'int' to 'GenericInner<int>.ReallyNested' is possible
tests/diagnostics/mismatching-types.slang(72): note: explicit conversion from 'int' to 'NonGenericOuter.GenericInner<int>.ReallyNested' is possible
tests/diagnostics/mismatching-types.slang(81): error 30019: expected an expression of type 'Texture1D<int>', got 'Texture1D<float>'
Texture1D<int> t1 = tex;
^~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Test that an `extension` applied to an interface type works as users expect

//TEST(compute):COMPARE_COMPUTE: -shaderobj
//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj

interface ICounter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// derived-struct-init-list.slang

//TEST(compute):COMPARE_COMPUTE:
//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj

// Test that use of an initializer list (especially
// an empty initializer list) is still possible
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// struct-inherit-interface-requirement.slang

//TEST(compute):COMPARE_COMPUTE: -shaderobj
//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj

// Test that a `struct` type can use an inherited
// member to satisfy an interface requirement.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// struct-inheritance.slang

//TEST(compute):COMPARE_COMPUTE: -shaderobj
//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj

// Test that we can define a `struct` type
// that inherits from another `struct`.
Expand Down

0 comments on commit 093bf71

Please sign in to comment.