From 63ef11c708904d8efe8f3d3f95733ebe73a012e8 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Wed, 24 Apr 2019 03:46:21 -0400 Subject: [PATCH] lang: Add a new type unification test I wanted to make sure that the type unification algorithm restricts the implementation of the class when included, when one of the polymorphic types is specified with a fixed type. It seems this works! I had the idea for this test while walking around aimlessly. --- .../TestAstFunc1/polydoubleincludewithtype.graph | 1 + .../TestAstFunc1/polydoubleincludewithtype/main.mcl | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.graph create mode 100644 lang/interpret_test/TestAstFunc1/polydoubleincludewithtype/main.mcl diff --git a/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.graph b/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.graph new file mode 100644 index 00000000..0a0315fb --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.graph @@ -0,0 +1 @@ +# err: err3: can't unify, invariant illogicality with equals: base kind does not match (2 != 5) diff --git a/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype/main.mcl b/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype/main.mcl new file mode 100644 index 00000000..dbc67bf6 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype/main.mcl @@ -0,0 +1,12 @@ +import "fmt" + +# note that the class can have two separate types for $b +include c1("t1", "hello") # len is 5 +include c1("t2", [13, 42, 0, -37,]) # len is 4 + +# specifying a fixed type for $b is a compile error, because it's sometimes str! +class c1($a, $b []str) { + test $a { + anotherstr => fmt.printf("len is: %d", len($b)), + } +}