Skip to content

Commit 083dc3e

Browse files
committed
[WGSL] Function parameters have incorrect scope
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
1 parent 666a7c0 commit 083dc3e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Source/WebGPU/WGSL/TypeCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ void TypeChecker::visit(AST::Function& function)
722722
ContextScope functionContext(this);
723723
for (unsigned i = 0; i < parameters.size(); ++i)
724724
introduceValue(function.parameters()[i].name(), parameters[i]);
725-
Base::visit(function.body());
725+
AST::Visitor::visit(function.body());
726726

727727
auto behaviors = analyze(function.body());
728728
if (behaviors.contains(Behavior::Next) && function.maybeReturnType())
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %not %wgslc | %check
2+
3+
fn testParameterScope(x: f32) -> i32
4+
{
5+
// CHECK-L: redeclaration of 'x'
6+
let x: i32 = 1;
7+
}

0 commit comments

Comments
 (0)