summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-04-20 16:56:33 -0700
committerGitHub <noreply@github.com>2018-04-20 16:56:33 -0700
commit2f782d403ae5729b6c93fbe92577ee01f7a8d608 (patch)
tree4f523901b8c07515dfc5d323873321746cf85ddf /tests/diagnostics
parentc73ccbc5616dff16ecacb9198f725f498a7e6c84 (diff)
Diagnose use of an implicit cast as an argument for an `out` parameter (#516)
Work on #499 Two big fixes here: * The logic for checking constraints on `out` arguments wasn't actually triggering because it relied on function parameters being given an `OutType` if they are marked `out`, but the code wasn't actually doing that. Fixing the computation of types for functions resolved that issue. * Next, I added a specific diagnostic to follow up the "expected an l-value" error to let the user know that their argument was implicitly converted, and that is why it doesn't count as an l-value in Slang's rules. I've added a test case to ensure that we retain this diagnostic until we can do a true fix for the issue. The right long-term fix is to have an AST representation of all the implicit casts involved (e.g., in both directions for an `inout` parameter), and then have the IR generate explicit code for the conversions in each direction (the `LoweredVal` representation can handle this sort of thing).
Diffstat (limited to 'tests/diagnostics')
-rw-r--r--tests/diagnostics/implicit-cast-lvalue.slang15
-rw-r--r--tests/diagnostics/implicit-cast-lvalue.slang.expected7
2 files changed, 22 insertions, 0 deletions
diff --git a/tests/diagnostics/implicit-cast-lvalue.slang b/tests/diagnostics/implicit-cast-lvalue.slang
new file mode 100644
index 000000000..4bf3c13b0
--- /dev/null
+++ b/tests/diagnostics/implicit-cast-lvalue.slang
@@ -0,0 +1,15 @@
+//TEST:SIMPLE:
+
+// Passing an argument for an `out` parameter such
+// that implicit conversion would be required in
+// both directions.
+
+void a(out uint x)
+{
+ x = 0;
+}
+
+void b(int y)
+{
+ a(y);
+}
diff --git a/tests/diagnostics/implicit-cast-lvalue.slang.expected b/tests/diagnostics/implicit-cast-lvalue.slang.expected
new file mode 100644
index 000000000..e5685fc51
--- /dev/null
+++ b/tests/diagnostics/implicit-cast-lvalue.slang.expected
@@ -0,0 +1,7 @@
+result code = -1
+standard error = {
+tests/diagnostics/implicit-cast-lvalue.slang(14): error 30047: argument passed to parameter '0' must be l-value.
+tests/diagnostics/implicit-cast-lvalue.slang(14): note 30048: argument was implicitly cast from 'int' to 'uint', and Slang does not support using an implicit cast as an l-value
+}
+standard output = {
+}