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>
This commit is contained in:
Ben Clayton 2022-12-14 21:18:23 +00:00 committed by Dawn LUCI CQ
parent 5addefb148
commit 55ceebec1e
2 changed files with 19 additions and 9 deletions

View File

@ -352,7 +352,7 @@ func (r *resolver) intrinsic(
case ast.Builtin, ast.Operator: case ast.Builtin, ast.Operator:
overload.ConstEvalFunction = overload.Decl.Name overload.ConstEvalFunction = overload.Decl.Name
case ast.Initializer: case ast.Initializer:
overload.ConstEvalFunction = "init" overload.ConstEvalFunction = "Init"
case ast.Converter: case ast.Converter:
overload.ConstEvalFunction = "Conv" overload.ConstEvalFunction = "Conv"
} }
@ -448,12 +448,15 @@ func (r *resolver) intrinsic(
} }
// fullyQualifiedName() resolves the ast.TemplatedName to a sem.FullyQualifiedName. // 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) { func (r *resolver) fullyQualifiedName(s *scope, arg ast.TemplatedName) (sem.FullyQualifiedName, error) {
target, err := r.lookupNamed(s, arg) target, err := r.lookupNamed(s, arg)
if err != nil { if err != nil {
return sem.FullyQualifiedName{}, err 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{ fqn := sem.FullyQualifiedName{
Target: target, Target: target,
TemplateArguments: make([]interface{}, len(arg.TemplateArgs)), TemplateArguments: make([]interface{}, len(arg.TemplateArgs)),

View File

@ -86,13 +86,6 @@ fn f<T: m>(P<T>) -> T`,
success, success,
}, { }, {
` `
type f32
type P<T>
match m: f32
fn f(P<m>)`,
success,
}, {
`
enum e { a } enum e { a }
match m: e.a match m: e.a
fn f(m)`, fn f(m)`,
@ -511,6 +504,20 @@ enum E { a b }
match m: E.a | E.b match m: E.a | E.b
conv F<M: m>(P<M>)`, conv F<M: m>(P<M>)`,
`file.txt:4:16 cannot use template enum 'E' as template number`, `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`,
}, },
} { } {