summaryrefslogtreecommitdiffstats
path: root/tests/bugs
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2020-03-24 14:04:30 -0700
committerGitHub <noreply@github.com>2020-03-24 14:04:30 -0700
commite71e75ab96fab6897f445c96a1de67e528676955 (patch)
treea034c36f4f6d78056d1f77117ca1dd9d1debb576 /tests/bugs
parent7b4e0e1892bad9f51677b191c69b01aee7403632 (diff)
Fix some bad behavior around static methods (#1289)
These are steps towards a fix for the problem of not being able to call a static method as follows: SomeType::someMethod(); One problem in the above is that the parser gets confused and parses an (anonynmous!) function declaration. This change doesn't address that problem, but *does* fix the problem that when checking fails to coerce `SomeType::someMethod` into a type it was triggering an unimplemented-feature exception rather than a real error message. Another problem was that if the above is re-written to try to avoid the parser bug: (SomeType::someMethod)(); we end up with a call where the base expression (the callee) is a `ParenExpr` and the code for handling calls wasn't expecting that. Instead, it sent the overload resolution logic into an unimplemented case that was bailing by throwing an arbitrary C++ exception instead of emitting a diagnostic. This latter issue was fixed in two ways. First, the code path that failed to emit a diagnostic now emits a reasonable one for the unimplemented feature (this still ends up being a fatal compiler error). Second, we properly handle the case of trying to call a `ParenExpr` by unwrapping it and using the base expression instead, so that `(<func>)(<args>)` is always treated the same as `<func>(<args>)`.
Diffstat (limited to 'tests/bugs')
-rw-r--r--tests/bugs/static-method.slang34
-rw-r--r--tests/bugs/static-method.slang.expected.txt4
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/bugs/static-method.slang b/tests/bugs/static-method.slang
new file mode 100644
index 000000000..dfb13b4a8
--- /dev/null
+++ b/tests/bugs/static-method.slang
@@ -0,0 +1,34 @@
+// static-method.slang
+
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+
+struct S
+{
+ static void doThing(in out int x, int y)
+ {
+ x += y;
+ }
+}
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out
+RWStructuredBuffer<int> outputBuffer : register(u0);
+
+int test(int t)
+{
+ // TODO: This case is currently being mis-handled by the parser
+// S::doThing(t, 0x10);
+
+ (S::doThing(t, 0x200));
+
+ (S::doThing)(t, 0x4000);
+
+ return t;
+}
+
+[numthreads(4)]
+void computeMain(uint3 tid : SV_DispatchThreadID)
+{
+ int val = tid.x;
+ val = test(val);
+ outputBuffer[tid.x] = val;
+}
diff --git a/tests/bugs/static-method.slang.expected.txt b/tests/bugs/static-method.slang.expected.txt
new file mode 100644
index 000000000..017c3bd20
--- /dev/null
+++ b/tests/bugs/static-method.slang.expected.txt
@@ -0,0 +1,4 @@
+4200
+4201
+4202
+4203