Skip to content

Commit

Permalink
Allow var/param names to be the same as type name. (#3850)
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe authored Mar 27, 2024
1 parent 8395acf commit b346a93
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
12 changes: 8 additions & 4 deletions source/slang/slang-check-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,8 @@ namespace Slang
}
else
{
initExpr = CheckExpr(initExpr);
SemanticsVisitor subVisitor(withDeclToExcludeFromLookup(varDecl));
initExpr = subVisitor.CheckExpr(initExpr);

// TODO: We might need some additional steps here to ensure
// that the type of the expression is one we are okay with
Expand All @@ -1568,7 +1569,8 @@ namespace Slang
{
// A variable with an explicit type is simpler, for the
// most part.
TypeExp typeExp = CheckUsableType(varDecl->type);
SemanticsVisitor subVisitor(withDeclToExcludeFromLookup(varDecl));
TypeExp typeExp = subVisitor.CheckUsableType(varDecl->type);
varDecl->type = typeExp;
if (varDecl->type.equals(m_astBuilder->getVoidType()))
{
Expand Down Expand Up @@ -6998,7 +7000,8 @@ namespace Slang
auto typeExpr = paramDecl->type;
if(typeExpr.exp)
{
typeExpr = CheckUsableType(typeExpr);
SemanticsVisitor subVisitor(withDeclToExcludeFromLookup(paramDecl));
typeExpr = subVisitor.CheckUsableType(typeExpr);
paramDecl->type = typeExpr;
checkMeshOutputDecl(paramDecl);
}
Expand Down Expand Up @@ -7640,7 +7643,8 @@ namespace Slang

void SemanticsDeclHeaderVisitor::visitPropertyDecl(PropertyDecl* decl)
{
decl->type = CheckUsableType(decl->type);
SemanticsVisitor subVisitor(withDeclToExcludeFromLookup(decl));
decl->type = subVisitor.CheckUsableType(decl->type);
visitAbstractStorageDeclCommon(decl);
checkVisibility(decl);
}
Expand Down
20 changes: 20 additions & 0 deletions tests/bugs/gh-3824.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//TEST:SIMPLE(filecheck=CHECK):-target spirv -emit-spirv-directly

// CHECK: OpEntryPoint

namespace example {
struct Example {}
}

struct Struct {
example::Example example;
}

void func(Struct Struct)
{
// Test parameter name to be the same as type name.
}

[numthreads(1,1,1)]
void main()
{}

0 comments on commit b346a93

Please sign in to comment.