From 03cda7bbb5dccd6d6be4bc9c5d11fcaef5031e18 Mon Sep 17 00:00:00 2001 From: Alasdair Date: Tue, 5 Nov 2019 20:03:28 +0000 Subject: Forbid types declared after a scattered union being used in clauses The following is therefore always forbidden ``` scattered union U enum E = A | B | C union clause U = Ctor : E ``` We attempt to detect when this occurs and include a hint indicating the likely reason why a 'Undefined type E' error might occur in this circumstance --- test/typecheck/fail/scattered_union_rec.expect | 16 ++++++++++++++++ test/typecheck/fail/scattered_union_rec.sail | 6 ++++++ 2 files changed, 22 insertions(+) create mode 100644 test/typecheck/fail/scattered_union_rec.expect create mode 100644 test/typecheck/fail/scattered_union_rec.sail (limited to 'test/typecheck') diff --git a/test/typecheck/fail/scattered_union_rec.expect b/test/typecheck/fail/scattered_union_rec.expect new file mode 100644 index 00000000..cbc9f70a --- /dev/null +++ b/test/typecheck/fail/scattered_union_rec.expect @@ -0,0 +1,16 @@ +Type error: +[scattered_union_rec.sail]:6:24-25 +6 |union clause U = Ctor : E +  | ^ +  | Undefined type E +  | This error was caused by: +  | [scattered_union_rec.sail]:6:0-25 +  | 6 |union clause U = Ctor : E +  |  |^-----------------------^ +  |  | Types are not well-formed within this type definition. Note that recursive types are forbidden. +  | This error was caused by: +  | [scattered_union_rec.sail]:6:13-14 +  | 6 |union clause U = Ctor : E +  |  | ^ +  |  | As this is a scattered union clause, this could also be caused by using a type defined after the 'scattered union' declaration +  | diff --git a/test/typecheck/fail/scattered_union_rec.sail b/test/typecheck/fail/scattered_union_rec.sail new file mode 100644 index 00000000..9f005f4e --- /dev/null +++ b/test/typecheck/fail/scattered_union_rec.sail @@ -0,0 +1,6 @@ + +scattered union U + +enum E = A | B | C + +union clause U = Ctor : E -- cgit v1.2.3