tools/intrinsic: Fix validation for type matchers
The tooling does not expect, nor can handel a type matcher to be used as a parameter or a direct template parameter to another type. Make this an error.
Change-Id: I28c04c00c7fa1cb5130c53215a90a59d660d6fa3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/114380
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/tools/src/tint/intrinsic/resolver/resolve.go b/tools/src/tint/intrinsic/resolver/resolve.go
index 59e4bfd..5725eda 100644
--- a/tools/src/tint/intrinsic/resolver/resolve.go
+++ b/tools/src/tint/intrinsic/resolver/resolve.go
@@ -352,7 +352,7 @@
case ast.Builtin, ast.Operator:
overload.ConstEvalFunction = overload.Decl.Name
case ast.Initializer:
- overload.ConstEvalFunction = "init"
+ overload.ConstEvalFunction = "Init"
case ast.Converter:
overload.ConstEvalFunction = "Conv"
}
@@ -448,12 +448,15 @@
}
// fullyQualifiedName() resolves the ast.TemplatedName to a sem.FullyQualifiedName.
+// The resolved name cannot be a TypeMatcher
func (r *resolver) fullyQualifiedName(s *scope, arg ast.TemplatedName) (sem.FullyQualifiedName, error) {
target, err := r.lookupNamed(s, arg)
if err != nil {
return sem.FullyQualifiedName{}, err
}
-
+ if _, ok := target.(*sem.TypeMatcher); ok {
+ return sem.FullyQualifiedName{}, fmt.Errorf("%v type matcher cannot be used directly here. Use a matcher constrained template argument", arg.Source)
+ }
fqn := sem.FullyQualifiedName{
Target: target,
TemplateArguments: make([]interface{}, len(arg.TemplateArgs)),
diff --git a/tools/src/tint/intrinsic/resolver/resolver_test.go b/tools/src/tint/intrinsic/resolver/resolver_test.go
index 5970314..15eac15 100644
--- a/tools/src/tint/intrinsic/resolver/resolver_test.go
+++ b/tools/src/tint/intrinsic/resolver/resolver_test.go
@@ -86,13 +86,6 @@
success,
}, {
`
-type f32
-type P<T>
-match m: f32
-fn f(P<m>)`,
- success,
- }, {
- `
enum e { a }
match m: e.a
fn f(m)`,
@@ -511,6 +504,20 @@
match m: E.a | E.b
conv F<M: m>(P<M>)`,
`file.txt:4:16 cannot use template enum 'E' as template number`,
+ }, {
+ `
+type f32
+type P<T>
+match m: f32
+fn f(m)`,
+ `file.txt:4:6 type matcher cannot be used directly here. Use a matcher constrained template argument`,
+ }, {
+ `
+type f32
+type P<T>
+match m: f32
+fn f(P<m>)`,
+ `file.txt:4:8 type matcher cannot be used directly here. Use a matcher constrained template argument`,
},
} {