diff options
| author | Julius Ikkala <julius.ikkala@gmail.com> | 2025-04-11 23:19:04 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-11 20:19:04 +0000 |
| commit | 88a180ba0aa57b2d0fb4956005db2ea73dc73420 (patch) | |
| tree | 4569f44c7549e941ea63ec71795442c7e3778b42 /tests/diagnostics | |
| parent | 1c719a998cf251c27a92975832ec4c1f37d63597 (diff) | |
Add a more specific diagnostic message when passing concrete value to interface-typed output parameter (#6788)
* More specific diagnostic for invalid concrete-to-interface arg coercion
* Add test for the new error message
* Fix typo in expected test result
Diffstat (limited to 'tests/diagnostics')
| -rw-r--r-- | tests/diagnostics/concrete-argument-to-output-interface.slang | 49 | ||||
| -rw-r--r-- | tests/diagnostics/concrete-argument-to-output-interface.slang.expected | 8 |
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/diagnostics/concrete-argument-to-output-interface.slang b/tests/diagnostics/concrete-argument-to-output-interface.slang new file mode 100644 index 000000000..cfe447d94 --- /dev/null +++ b/tests/diagnostics/concrete-argument-to-output-interface.slang @@ -0,0 +1,49 @@ +//DIAGNOSTIC_TEST:SIMPLE: + +interface IThing +{ + [mutating] + void f(); + + void g(); +} + +struct MyThing: IThing +{ + int a = 0; + + [mutating] + void f() + { + a = 10; + } + + void g() {} +} + +void g(IThing x) +{ + x.g(); +} + +void f(inout IThing x) +{ + x.f(); +} + +void h<T:IThing>(inout T x) +{ + x.f(); +} + +void entry() +{ + MyThing concrete; + IThing interfaceTyped = MyThing(); + + g(interfaceTyped); // No error + g(concrete); // No error + f(interfaceTyped); // No error + h(concrete); // No error + f(concrete); // ERROR! +} diff --git a/tests/diagnostics/concrete-argument-to-output-interface.slang.expected b/tests/diagnostics/concrete-argument-to-output-interface.slang.expected new file mode 100644 index 000000000..b979d01a3 --- /dev/null +++ b/tests/diagnostics/concrete-argument-to-output-interface.slang.expected @@ -0,0 +1,8 @@ +result code = -1 +standard error = { +tests/diagnostics/concrete-argument-to-output-interface.slang(48): error 30077: argument passed to parameter 'x' is of concrete type 'MyThing', but interface-typed output parameters require interface-typed arguments. To allow passing a concrete type to this function, you can replace 'IThing x' with a generic 'T x' and a 'where T : IThing' constraint. + f(concrete); // ERROR! + ^ +} +standard output = { +} |
