Skip to content

Commit

Permalink
[WGSL] Function parameters have incorrect scope
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=274602
rdar://128625182

Reviewed by Mike Wyrzykowski.

The parameters were being placed in a separate scope from the function local variables,
allowing a local variable to shadow a parameter, which shouldn't be valid according to
the spec.

* Source/WebGPU/WGSL/TypeCheck.cpp:
(WGSL::TypeChecker::visit):
* Source/WebGPU/WGSL/tests/invalid/shadowing.wgsl: Added.

Canonical link: https://commits.webkit.org/279262@main
  • Loading branch information
tadeuzagallo committed May 24, 2024
1 parent 666a7c0 commit 083dc3e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/WebGPU/WGSL/TypeCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ void TypeChecker::visit(AST::Function& function)
ContextScope functionContext(this);
for (unsigned i = 0; i < parameters.size(); ++i)
introduceValue(function.parameters()[i].name(), parameters[i]);
Base::visit(function.body());
AST::Visitor::visit(function.body());

auto behaviors = analyze(function.body());
if (behaviors.contains(Behavior::Next) && function.maybeReturnType())
Expand Down
7 changes: 7 additions & 0 deletions Source/WebGPU/WGSL/tests/invalid/shadowing.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %not %wgslc | %check

fn testParameterScope(x: f32) -> i32
{
// CHECK-L: redeclaration of 'x'
let x: i32 = 1;
}

0 comments on commit 083dc3e

Please sign in to comment.