From 492c6f2fd1a64c9d60a968b55bfd1000cc2ae8e7 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 4 Apr 2023 15:29:36 -0700 Subject: Diagnose on using assignment as predicate expr. (#2774) Co-authored-by: Yong He --- tests/diagnostics/assign-in-if.slang | 12 ++++++++++++ tests/diagnostics/assign-in-if.slang.expected | 14 ++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/diagnostics/assign-in-if.slang create mode 100644 tests/diagnostics/assign-in-if.slang.expected (limited to 'tests/diagnostics') diff --git a/tests/diagnostics/assign-in-if.slang b/tests/diagnostics/assign-in-if.slang new file mode 100644 index 000000000..ef2222365 --- /dev/null +++ b/tests/diagnostics/assign-in-if.slang @@ -0,0 +1,12 @@ +//DIAGNOSTIC_TEST:REFLECTION:-stage compute -entry main -target hlsl + +[numthreads(1, 1, 1)] +void main( + uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int a = 1; + if (a = 0) // error + {} + if ((a = 0)) // ok. + {} +} \ No newline at end of file diff --git a/tests/diagnostics/assign-in-if.slang.expected b/tests/diagnostics/assign-in-if.slang.expected new file mode 100644 index 000000000..373072d66 --- /dev/null +++ b/tests/diagnostics/assign-in-if.slang.expected @@ -0,0 +1,14 @@ +result code = 1 +standard error = { +tests/diagnostics/assign-in-if.slang(8): error 30057: use an assignment operation as predicate expression is not allowed, wrap the assignment with '()' to clarify the intent. + if (a = 0) // error + ^ +tests/diagnostics/assign-in-if.slang(8): warning 30081: implicit conversion from 'int' to 'bool' is not recommended + if (a = 0) // error + ^ +tests/diagnostics/assign-in-if.slang(10): warning 30081: implicit conversion from 'int' to 'bool' is not recommended + if ((a = 0)) // ok. + ^ +} +standard output = { +} -- cgit v1.2.3