diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2020-04-10 09:20:36 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-10 09:20:36 -0700 |
| commit | 2d16fcd4377fb4b0f350e1c12afc6002368499dc (patch) | |
| tree | 21c1cb9916948fc2ce018de53f46bbe8edc9f12f /tests/bugs | |
| parent | a01c09c3934d3f859bf4bea6b4e583f25291b643 (diff) | |
Fix crashing bug when using overloaded name as generic arg (#1315)
If somebody defines two `struct` types with the same name:
```hlsl
struct A {}
// ...
struct A {}
```
and then tries to use that name when specializing a generic function:
```hlsl
void doThing<T>() { ... }
// ...
doThing<A>();
```
then the Slang front-end currently crashes, which leads to it not diagnosing the original problem (the conflicting declarations of `A`).
This change fixes up the checking of generic arguments so that it properly fills in dummy "error" arguments in place of missing or incorrect arguments, and thus guarantees that the generic substitution it creates will at least be usable for the next steps of checking (rather than leaving null pointers in the substitution).
This change also fixes up the error message for the case where a generic application like `F<A>` is formed where `F` is not a generic. We already had a more refined diagnostic defined for that case, but for some reason the site in the code where we ought to use it was still issuing an internal compiler error around an unimplemented feature.
This chagne includes a diagnostic test case to cover both of the above fixes.
Diffstat (limited to 'tests/bugs')
| -rw-r--r-- | tests/bugs/generic-type-arg-overloaded.slang | 33 | ||||
| -rw-r--r-- | tests/bugs/generic-type-arg-overloaded.slang.expected | 11 |
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/bugs/generic-type-arg-overloaded.slang b/tests/bugs/generic-type-arg-overloaded.slang new file mode 100644 index 000000000..99150d2f0 --- /dev/null +++ b/tests/bugs/generic-type-arg-overloaded.slang @@ -0,0 +1,33 @@ +// generic-type-arg-overloaded.slang + +//DIAGNOSTIC_TEST:SIMPLE: + +// Regression test to confirm that type checker +// doesn't crash when an overloaded identifier +// is used as a generic type argument. + +interface IThing { int getVal(); } + +struct Stuff : IThing { int getVal() { return 1; } } + +// Conflicting declaration: +struct Stuff {} + +int util<T : IThing>() { return 1; } + +struct G {} +int nonGeneric() { return 2; } + +int test() +{ + // This call should note the ambiguity, + // rather than crash. + // + return util<Stuff>() + + // Adding an extra call to also test the + // case of trying to speicalize something + // like a generic when it isn't one. + // + + nonGeneric<G>(); +} diff --git a/tests/bugs/generic-type-arg-overloaded.slang.expected b/tests/bugs/generic-type-arg-overloaded.slang.expected new file mode 100644 index 000000000..518abc2b1 --- /dev/null +++ b/tests/bugs/generic-type-arg-overloaded.slang.expected @@ -0,0 +1,11 @@ +result code = -1 +standard error = { +tests/bugs/generic-type-arg-overloaded.slang(14): error 30200: declaration of 'Stuff' conflicts with existing declaration +tests/bugs/generic-type-arg-overloaded.slang(11): note: see previous declaration of 'Stuff' +tests/bugs/generic-type-arg-overloaded.slang(26): error 39999: ambiguous reference to 'Stuff' +tests/bugs/generic-type-arg-overloaded.slang(14): note 39999: candidate: Stuff +tests/bugs/generic-type-arg-overloaded.slang(11): note 39999: candidate: Stuff +tests/bugs/generic-type-arg-overloaded.slang(32): error 39999: expected a generic when using '<...>' (found: '() -> int') +} +standard output = { +} |
