tests: add a regression test for the inter module generics inference

pull/7078/head
Delyan Angelov 2020-12-01 08:05:28 +02:00
parent a7d917474d
commit fe0ded9a91
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,8 @@
module genericmodule
pub fn take<T>(a bool, b T, c T) T {
if a {
return b
}
return c
}

View File

@ -0,0 +1,35 @@
module main
import genericmodule
fn test_generic_function_from_another_module() {
v1 := genericmodule.take<int>(true, 10, 20)
assert typeof(v1) == 'int'
assert v1 == 10
v2 := genericmodule.take<int>(false, 10, 20)
assert v2 == 20
}
fn test_generic_type_inference_from_another_module() {
v1 := genericmodule.take(true, 10, 20)
assert typeof(v1) == 'int'
assert v1 == 10
v2 := genericmodule.take(false, 10, 20)
assert v2 == 20
}
fn test_inference_with_strings() {
v1 := genericmodule.take(true, 'abc', 'def')
assert typeof(v1) == 'string'
assert v1 == 'abc'
v2 := genericmodule.take(false, 'abc', 'def')
assert v2 == 'def'
}
fn test_inference_with_f64() {
v1 := genericmodule.take(true, f64(123), 345)
assert typeof(v1) == 'f64'
assert v1 == 123
v2 := genericmodule.take(false, f64(123), 345)
assert v2 == 345
}