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.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
# err: err3: can't unify, invariant illogicality with equals: base kind does not match (2 != 5)
|
||||
@@ -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)),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user