From 5705c13d1dbe98ee63acc75a0436128e2a7de6e8 Mon Sep 17 00:00:00 2001 From: Alasdair Armstrong Date: Tue, 20 Nov 2018 18:06:47 +0000 Subject: Add a test case for a struct with a constrained type variable --- test/typecheck/pass/constrained_struct.sail | 12 ++++++++++++ test/typecheck/pass/constrained_struct/v1.expect | 5 +++++ test/typecheck/pass/constrained_struct/v1.sail | 12 ++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 test/typecheck/pass/constrained_struct.sail create mode 100644 test/typecheck/pass/constrained_struct/v1.expect create mode 100644 test/typecheck/pass/constrained_struct/v1.sail diff --git a/test/typecheck/pass/constrained_struct.sail b/test/typecheck/pass/constrained_struct.sail new file mode 100644 index 00000000..64b2287f --- /dev/null +++ b/test/typecheck/pass/constrained_struct.sail @@ -0,0 +1,12 @@ +default Order dec + +$include + +struct MyStruct 'n, 'n in {32, 64} = { + field: bits('n) +} + +type MyStruct32 = MyStruct(32) +type MyStruct64 = MyStruct(64) + +let x : MyStruct64 = struct { field = 0xFFFF_FFFF_FFFF_FFFF } diff --git a/test/typecheck/pass/constrained_struct/v1.expect b/test/typecheck/pass/constrained_struct/v1.expect new file mode 100644 index 00000000..5173ef0b --- /dev/null +++ b/test/typecheck/pass/constrained_struct/v1.expect @@ -0,0 +1,5 @@ +Type error at file "constrained_struct/v1.sail", line 10, character 19 to line 10, character 26 + +type MyStruct64 = MyStruct(65) + +Could not prove (65 = 32 | 65 = 64) for type constructor MyStruct diff --git a/test/typecheck/pass/constrained_struct/v1.sail b/test/typecheck/pass/constrained_struct/v1.sail new file mode 100644 index 00000000..62fc1c01 --- /dev/null +++ b/test/typecheck/pass/constrained_struct/v1.sail @@ -0,0 +1,12 @@ +default Order dec + +$include + +struct MyStruct 'n, 'n in {32, 64} = { + field: bits('n) +} + +type MyStruct32 = MyStruct(32) +type MyStruct64 = MyStruct(65) + +let x : MyStruct64 = struct { field = 0b1 @ 0xFFFF_FFFF_FFFF_FFFF } -- cgit v1.2.3