summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-07-07 03:52:00 +0800
committerGitHub <noreply@github.com>2023-07-06 15:52:00 -0400
commitcdfea42f1b28c6ec7b13500a64be823f67bf8e0a (patch)
tree4444c21ac369ce8f4c99370fcd47153eeb35581f /tests
parent4a88139a86596fd1a546af84ab3210ea3013c58d (diff)
Fix erroneous error claiming variable is being used before its declaration (#2958)
* Simplify type of diagnoseImpl * Show source line for Note diagnostics, opting out of this where appropriate * Make declared after use diagnostic clearer * Fix erroneous error claiming variable is being used before its declaration Closes https://github.com/shader-slang/slang/issues/2936 * Fix build on msvc --------- Co-authored-by: jsmall-nvidia <jsmall@nvidia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/bugs/generic-type-arg-overloaded.slang.expected6
-rw-r--r--tests/bugs/gh-2936.slang53
-rw-r--r--tests/diagnostics/bad-operator-call.slang.expected4
-rw-r--r--tests/diagnostics/enum-implicit-conversion.slang.expected4
-rw-r--r--tests/diagnostics/extension-visibility.slang.expected2
-rw-r--r--tests/diagnostics/generic-type-inference-fail.slang.expected2
-rw-r--r--tests/diagnostics/gh-38-vs.hlsl.expected2
-rw-r--r--tests/diagnostics/interface-requirement-not-satisfied.slang.expected2
-rw-r--r--tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang.expected2
-rw-r--r--tests/diagnostics/local-used-before-declared.slang.expected6
-rw-r--r--tests/diagnostics/local-used-in-own-declaration.slang.expected4
-rw-r--r--tests/diagnostics/overlapping-bindings.slang.expected2
-rw-r--r--tests/diagnostics/parameter-already-defined.slang.expected2
-rw-r--r--tests/diagnostics/single-target-intrinsic.slang.expected2
-rw-r--r--tests/diagnostics/variable-redeclaration.slang.expected12
-rw-r--r--tests/preprocessor/define-redefine.slang.expected2
-rw-r--r--tests/preprocessor/include-multiple.slang.expected4
-rw-r--r--tests/preprocessor/output-includes.slang.expected4
18 files changed, 110 insertions, 5 deletions
diff --git a/tests/bugs/generic-type-arg-overloaded.slang.expected b/tests/bugs/generic-type-arg-overloaded.slang.expected
index 390c4fe00..1c41da717 100644
--- a/tests/bugs/generic-type-arg-overloaded.slang.expected
+++ b/tests/bugs/generic-type-arg-overloaded.slang.expected
@@ -4,11 +4,17 @@ tests/bugs/generic-type-arg-overloaded.slang(14): error 30200: declaration of 'S
struct Stuff {}
^~~~~
tests/bugs/generic-type-arg-overloaded.slang(11): note: see previous declaration of 'Stuff'
+struct Stuff : IThing { int getVal() { return 1; } }
+ ^~~~~
tests/bugs/generic-type-arg-overloaded.slang(26): error 39999: ambiguous reference to 'Stuff'
return util<Stuff>()
^~~~~
tests/bugs/generic-type-arg-overloaded.slang(14): note 39999: candidate: struct Stuff
+struct Stuff {}
+ ^~~~~
tests/bugs/generic-type-arg-overloaded.slang(11): note 39999: candidate: struct Stuff
+struct Stuff : IThing { int getVal() { return 1; } }
+ ^~~~~
tests/bugs/generic-type-arg-overloaded.slang(32): error 39999: expected a generic when using '<...>' (found: '() -> int')
+ nonGeneric<G>();
^~~~~~~~~~
diff --git a/tests/bugs/gh-2936.slang b/tests/bugs/gh-2936.slang
new file mode 100644
index 000000000..20bfa1924
--- /dev/null
+++ b/tests/bugs/gh-2936.slang
@@ -0,0 +1,53 @@
+//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -shaderobj -output-using-type
+
+// CHECK: 4
+// CHECK-NEXT: 99
+// CHECK-NEXT: 111
+// CHECK-NEXT: 40
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(1, 1, 1)]
+void computeMain()
+{
+ outputBuffer[0] = f();
+ outputBuffer[1] = g();
+ outputBuffer[2] = h();
+ outputBuffer[3] = k(30, 40);
+}
+
+static let x = 1;
+
+func f() -> int
+{
+ let y = x; // should refer to the global x
+ let x = 3;
+ return x + y; // should refer to the local x
+}
+func g() -> int
+{
+ // Can we shadow this keyword
+ int out;
+ out = 99;
+ return out;
+}
+
+static var input = 999;
+func h() -> int
+{
+ // This should still parse as an identifier (it's a keyword, being shadowed
+ // by something in a parent scope)
+ input = 10;
+ int input = input;
+ input += 101;
+ return input;
+}
+
+int k(int a, int b)
+{
+ int umax = max(a, b);
+
+ int max = umax;
+ return max;
+}
diff --git a/tests/diagnostics/bad-operator-call.slang.expected b/tests/diagnostics/bad-operator-call.slang.expected
index 82eaef848..3abca8f23 100644
--- a/tests/diagnostics/bad-operator-call.slang.expected
+++ b/tests/diagnostics/bad-operator-call.slang.expected
@@ -22,6 +22,8 @@ core.meta.slang(2425): note 39999: candidate: func +(half, half) -> half
core.meta.slang(2417): note 39999: candidate: func +(intptr_t, intptr_t) -> intptr_t
core.meta.slang(2409): note 39999: candidate: func +(int64_t, int64_t) -> int64_t
tests/diagnostics/bad-operator-call.slang(20): note 39999: 3 more overload candidates
+ a = a + b;
+ ^
tests/diagnostics/bad-operator-call.slang(22): error 39999: no overload for '~' applicable to arguments of type (S)
a = ~b;
^
@@ -61,6 +63,8 @@ core.meta.slang(2469): note 39999: candidate: func +<3>(uint, uint3) -> uint3
core.meta.slang(2465): note 39999: candidate: func +(uint, uint) -> uint
core.meta.slang(2463): note 39999: candidate: func +<4>(uint16_t4, uint16_t) -> uint16_t4
tests/diagnostics/bad-operator-call.slang(33): note 39999: 29 more overload candidates
+ d = c + d;
+ ^
}
standard output = {
}
diff --git a/tests/diagnostics/enum-implicit-conversion.slang.expected b/tests/diagnostics/enum-implicit-conversion.slang.expected
index 61164bbaa..376dab7e6 100644
--- a/tests/diagnostics/enum-implicit-conversion.slang.expected
+++ b/tests/diagnostics/enum-implicit-conversion.slang.expected
@@ -16,7 +16,11 @@ tests/diagnostics/enum-implicit-conversion.slang(42): error 39999: ambiguous cal
int z = foo(c);
^
tests/diagnostics/enum-implicit-conversion.slang(18): note 39999: candidate: func foo(uint) -> int
+int foo(uint x) { return x * 256 * 16; }
+ ^~~
tests/diagnostics/enum-implicit-conversion.slang(17): note 39999: candidate: func foo(int) -> int
+int foo(int x) { return x * 16; }
+ ^~~
}
standard output = {
}
diff --git a/tests/diagnostics/extension-visibility.slang.expected b/tests/diagnostics/extension-visibility.slang.expected
index fb3aaa999..732ff4189 100644
--- a/tests/diagnostics/extension-visibility.slang.expected
+++ b/tests/diagnostics/extension-visibility.slang.expected
@@ -4,6 +4,8 @@ tests/diagnostics/extension-visibility.slang(17): error 39999: could not special
return helper(thing);
^
tests/diagnostics/extension-visibility-a.slang(14): note 39999: see declaration of func helper<T>(T) -> int
+int helper<T : IThing>(T thing)
+ ^~~~~~
}
standard output = {
}
diff --git a/tests/diagnostics/generic-type-inference-fail.slang.expected b/tests/diagnostics/generic-type-inference-fail.slang.expected
index 3f9753d68..17cb28ca2 100644
--- a/tests/diagnostics/generic-type-inference-fail.slang.expected
+++ b/tests/diagnostics/generic-type-inference-fail.slang.expected
@@ -4,6 +4,8 @@ tests/diagnostics/generic-type-inference-fail.slang(66): error 39999: could not
var obj3 = CreateT_Assoc_Inner(1); // ERROR.
^
tests/diagnostics/generic-type-inference-fail.slang(18): note 39999: see declaration of func CreateT_Assoc_Inner<T>(int) -> T.TAssoc
+T.TAssoc CreateT_Assoc_Inner<T:IInterface>(int inVal)
+ ^~~~~~~~~~~~~~~~~~~
}
standard output = {
}
diff --git a/tests/diagnostics/gh-38-vs.hlsl.expected b/tests/diagnostics/gh-38-vs.hlsl.expected
index bc33e43aa..30d9516d5 100644
--- a/tests/diagnostics/gh-38-vs.hlsl.expected
+++ b/tests/diagnostics/gh-38-vs.hlsl.expected
@@ -4,6 +4,8 @@ tests/diagnostics/gh-38-fs.hlsl(5): warning 39001: explicit binding for paramete
Texture2D overlappingB : register(t0);
^~~~~~~~~~~~
tests/diagnostics/gh-38-vs.hlsl(5): note: see declaration of 'overlappingA'
+Texture2D overlappingA : register(t0);
+ ^~~~~~~~~~~~
}
standard output = {
}
diff --git a/tests/diagnostics/interface-requirement-not-satisfied.slang.expected b/tests/diagnostics/interface-requirement-not-satisfied.slang.expected
index 464ffde25..d9a832794 100644
--- a/tests/diagnostics/interface-requirement-not-satisfied.slang.expected
+++ b/tests/diagnostics/interface-requirement-not-satisfied.slang.expected
@@ -4,6 +4,8 @@ tests/diagnostics/interface-requirement-not-satisfied.slang(10): error 38100: ty
struct T : IFoo
^~~~
tests/diagnostics/interface-requirement-not-satisfied.slang(7): note: see declaration of 'bar'
+ void bar();
+ ^~~
}
standard output = {
}
diff --git a/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang.expected b/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang.expected
index cc4f310ad..3ac7dfa5f 100644
--- a/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang.expected
+++ b/tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang.expected
@@ -4,6 +4,8 @@ tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang(10): error
struct Counter : IThing
^~~~~~
tests/diagnostics/interfaces/mutating-impl-of-non-mutating-req.slang(7): note: see declaration of 'processValue'
+ int processValue(int inValue);
+ ^~~~~~~~~~~~
}
standard output = {
}
diff --git a/tests/diagnostics/local-used-before-declared.slang.expected b/tests/diagnostics/local-used-before-declared.slang.expected
index 2317c4a67..52a15b7de 100644
--- a/tests/diagnostics/local-used-before-declared.slang.expected
+++ b/tests/diagnostics/local-used-before-declared.slang.expected
@@ -1,8 +1,8 @@
result code = -1
standard error = {
-tests/diagnostics/local-used-before-declared.slang(14): fatal error 39999: local variable 'd' is being used before its declaration.
- int d = 0;
- ^
+tests/diagnostics/local-used-before-declared.slang(13): error 30015: undefined identifier 'd'.
+ float c = d + 1.0;
+ ^
}
standard output = {
}
diff --git a/tests/diagnostics/local-used-in-own-declaration.slang.expected b/tests/diagnostics/local-used-in-own-declaration.slang.expected
index 72582e0a9..1517663c0 100644
--- a/tests/diagnostics/local-used-in-own-declaration.slang.expected
+++ b/tests/diagnostics/local-used-in-own-declaration.slang.expected
@@ -1,8 +1,8 @@
result code = -1
standard error = {
-tests/diagnostics/local-used-in-own-declaration.slang(12): fatal error 39999: local variable 'e' is being used before its declaration.
+tests/diagnostics/local-used-in-own-declaration.slang(12): error 30015: undefined identifier 'e'.
int e = e;
- ^
+ ^
}
standard output = {
}
diff --git a/tests/diagnostics/overlapping-bindings.slang.expected b/tests/diagnostics/overlapping-bindings.slang.expected
index bce542b2b..593f99fb4 100644
--- a/tests/diagnostics/overlapping-bindings.slang.expected
+++ b/tests/diagnostics/overlapping-bindings.slang.expected
@@ -4,6 +4,8 @@ tests/diagnostics/overlapping-bindings.slang(9): warning 39001: explicit binding
Texture2D b : register(t0);
^
tests/diagnostics/overlapping-bindings.slang(7): note: see declaration of 'a'
+Texture2D a : register(t0);
+ ^
}
standard output = {
}
diff --git a/tests/diagnostics/parameter-already-defined.slang.expected b/tests/diagnostics/parameter-already-defined.slang.expected
index fa9ffb581..42156a020 100644
--- a/tests/diagnostics/parameter-already-defined.slang.expected
+++ b/tests/diagnostics/parameter-already-defined.slang.expected
@@ -4,6 +4,8 @@ tests/diagnostics/parameter-already-defined.slang(4): error 30200: declaration o
int foo( int a, float a ) { return 0; }
^
tests/diagnostics/parameter-already-defined.slang(4): note: see previous declaration of 'a'
+int foo( int a, float a ) { return 0; }
+ ^
}
standard output = {
}
diff --git a/tests/diagnostics/single-target-intrinsic.slang.expected b/tests/diagnostics/single-target-intrinsic.slang.expected
index d7662c50e..824cd0805 100644
--- a/tests/diagnostics/single-target-intrinsic.slang.expected
+++ b/tests/diagnostics/single-target-intrinsic.slang.expected
@@ -4,6 +4,8 @@ tests/diagnostics/single-target-intrinsic.slang(13): error 30201: function 'doTh
T doThing<T>(T in);
^~~~~~~
tests/diagnostics/single-target-intrinsic.slang(10): note: see previous definition of 'doThing'
+T doThing<T>(T in);
+ ^~~~~~~
}
standard output = {
}
diff --git a/tests/diagnostics/variable-redeclaration.slang.expected b/tests/diagnostics/variable-redeclaration.slang.expected
index d18e5fb2a..944037b1c 100644
--- a/tests/diagnostics/variable-redeclaration.slang.expected
+++ b/tests/diagnostics/variable-redeclaration.slang.expected
@@ -4,23 +4,35 @@ tests/diagnostics/variable-redeclaration.slang(14): error 30200: declaration of
static Texture2D gA;
^~
tests/diagnostics/variable-redeclaration.slang(12): note: see previous declaration of 'gA'
+static int gA;
+ ^~
tests/diagnostics/variable-redeclaration.slang(44): error 30200: declaration of 'f' conflicts with existing declaration
float f;
^
tests/diagnostics/variable-redeclaration.slang(43): note: see previous declaration of 'f'
+ int f;
+ ^
tests/diagnostics/variable-redeclaration.slang(51): error 30200: declaration of 'size' conflicts with existing declaration
float size)
^~~~
tests/diagnostics/variable-redeclaration.slang(50): note: see previous declaration of 'size'
+ int size,
+ ^~~~
tests/diagnostics/variable-redeclaration.slang(21): error 30200: declaration of 'y' conflicts with existing declaration
int y = x;
^
tests/diagnostics/variable-redeclaration.slang(20): note: see previous declaration of 'y'
+ int y = x;
+ ^
tests/diagnostics/variable-redeclaration.slang(53): error 39999: ambiguous reference to 'size'
return size;
^~~~
tests/diagnostics/variable-redeclaration.slang(51): note 39999: candidate: float size
+ float size)
+ ^~~~
tests/diagnostics/variable-redeclaration.slang(50): note 39999: candidate: int size
+ int size,
+ ^~~~
}
standard output = {
}
diff --git a/tests/preprocessor/define-redefine.slang.expected b/tests/preprocessor/define-redefine.slang.expected
index 9b376bfe8..682e024ea 100644
--- a/tests/preprocessor/define-redefine.slang.expected
+++ b/tests/preprocessor/define-redefine.slang.expected
@@ -4,6 +4,8 @@ tests/preprocessor/define-redefine.slang(10): warning 15400: redefinition of mac
#define FOO 2.0f
^~~
tests/preprocessor/define-redefine.slang(6): note: see previous definition of 'FOO'
+#define FOO 1.0f
+ ^~~
}
standard output = {
}
diff --git a/tests/preprocessor/include-multiple.slang.expected b/tests/preprocessor/include-multiple.slang.expected
index f254ecf2f..f9facb349 100644
--- a/tests/preprocessor/include-multiple.slang.expected
+++ b/tests/preprocessor/include-multiple.slang.expected
@@ -4,10 +4,14 @@ tests/preprocessor/include-a.slang.h(3): error 30201: function 'bar' already has
int bar() { return foo(); }
^~~
tests/preprocessor/include-a.slang.h(3): note: see previous definition of 'bar'
+int bar() { return foo(); }
+ ^~~
tests/preprocessor/include-a.slang.h(3): error 30201: function 'bar' already has a body
int bar() { return foo(); }
^~~
tests/preprocessor/include-a.slang.h(3): note: see previous definition of 'bar'
+int bar() { return foo(); }
+ ^~~
}
standard output = {
}
diff --git a/tests/preprocessor/output-includes.slang.expected b/tests/preprocessor/output-includes.slang.expected
index 84f0a4411..f2fbb64f2 100644
--- a/tests/preprocessor/output-includes.slang.expected
+++ b/tests/preprocessor/output-includes.slang.expected
@@ -10,10 +10,14 @@ tests/preprocessor/include-a.slang.h(3): error 30201: function 'bar' already has
int bar() { return foo(); }
^~~
tests/preprocessor/include-a.slang.h(3): note: see previous definition of 'bar'
+int bar() { return foo(); }
+ ^~~
tests/preprocessor/include-a.slang.h(3): error 30201: function 'bar' already has a body
int bar() { return foo(); }
^~~
tests/preprocessor/include-a.slang.h(3): note: see previous definition of 'bar'
+int bar() { return foo(); }
+ ^~~
}
standard output = {
}