-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tuple literal type covariance (#1175)
Enhancements: - Tuple literal type covariance (closes #1166) - Improved type inference for list literals and if expressions (see #1173)
- Loading branch information
Showing
56 changed files
with
1,311 additions
and
617 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
] | ||
}, | ||
"ghul.compiler": { | ||
"version": "0.8.42", | ||
"version": "0.8.43", | ||
"commands": [ | ||
"ghul-compiler" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
integration-tests/parse/function-nesting-error-1/err.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
test.ghul: 13,13..13,28: error: expected function literal formal arguments | ||
test.ghul: 15,24..15,29: error: cannot return value of type Ghul.int from function of type Test.IncompleteFunction.Test | ||
test.ghul: 12,9..12,24: error: expected function literal formal arguments | ||
test.ghul: 14,20..14,25: error: cannot return value of type Ghul.int where Test expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
{ | ||
"compiler": "dotnet ../../../publish/ghul.dll", | ||
"source": [ | ||
"." | ||
] | ||
"compiler": "dotnet ../../../publish/ghul.dll" | ||
} |
60 changes: 29 additions & 31 deletions
60
integration-tests/parse/function-nesting-error-1/test.ghul
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,36 @@ | ||
namespace Test.IncompleteFunction is | ||
class Test is | ||
count: int; | ||
class Test is | ||
count: int; | ||
|
||
f(i: int) -> int is | ||
return 0 | ||
si | ||
|
||
g(i:int) -> int is | ||
count = count - 1; | ||
return 0; | ||
f(i: int) -> int is | ||
return 0 | ||
si | ||
|
||
"asdf" (i: int) -> Test is | ||
count = count - 1; | ||
return count; | ||
si | ||
g(i:int) -> int is | ||
count = count - 1; | ||
return 0; | ||
|
||
"asdf" (i: int) -> Test is | ||
count = count - 1; | ||
return count; | ||
si | ||
|
||
i(i: int) -> Test is | ||
let x = if count > 0 then | ||
"count is {count}" | ||
else | ||
"count is 0" | ||
fi; | ||
|
||
if count > 0 then | ||
return null | ||
else | ||
return null | ||
fi | ||
si | ||
si | ||
|
||
i(i: int) -> Test is | ||
let x = if count > 0 then | ||
"count is {count}" | ||
else | ||
"count is 0" | ||
fi; | ||
|
||
j(i: int) -> int is | ||
return count | ||
si | ||
if count > 0 then | ||
return null | ||
else | ||
return null | ||
fi | ||
si | ||
|
||
j(i: int) -> int is | ||
return count | ||
si | ||
si | ||
si |
1 change: 0 additions & 1 deletion
1
integration-tests/semantic/anonymous-function-argument-type-inference/run.expected
This file was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
integration-tests/semantic/function-return-type-check/err.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
test.ghul: 22,20..22,27: error: cannot return value of type Ghul.string from function of type Ghul.int | ||
test.ghul: 29,32..29,39: error: cannot return value of type Ghul.string from function of type Ghul.int | ||
test.ghul: 32,20..32,24: error: cannot return value from function of void type | ||
test.ghul: 37,26..37,31: error: cannot return value from function of void type | ||
test.ghul: 11,16..11,23: error: cannot return value of type Ghul.string where Ghul.int expected | ||
test.ghul: 18,28..18,35: error: cannot return value of type Ghul.string where Ghul.int expected | ||
test.ghul: 21,16..21,20: error: cannot return value from function of void type | ||
test.ghul: 26,22..26,27: error: cannot return value from function of void type |
5 changes: 1 addition & 4 deletions
5
integration-tests/semantic/function-return-type-check/ghul.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
{ | ||
"compiler": "dotnet ../../../publish/ghul.dll", | ||
"source": [ | ||
"." | ||
] | ||
"compiler": "dotnet ../../../publish/ghul.dll" | ||
} |
54 changes: 21 additions & 33 deletions
54
integration-tests/semantic/function-return-type-check/test.ghul
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,33 @@ | ||
namespace Test is | ||
use Std = IO.Std; | ||
|
||
class Main is | ||
entry() static is | ||
return; | ||
si | ||
|
||
test_int_1() -> int static is | ||
return 1234; // OK - correct type | ||
|
||
return "Hello"; // Error: string not assignable to return type int | ||
|
||
return; // Warning: no return expression means default value for int will be returned | ||
si | ||
|
||
test_int_2() -> int => 1234; // OK - correct type | ||
|
||
test_int_3() -> int => "Hello"; // Error: string not assignable to int | ||
|
||
test_void_1() is | ||
return 1234; // Error: any value returned from void function is incorrect | ||
|
||
use Std = IO.Std; | ||
|
||
class Main is | ||
entry() static is | ||
|
||
|
||
return; | ||
si | ||
|
||
test_int_1() -> int static is | ||
return 1234; // OK - correct type | ||
|
||
return "Hello"; // Error: string not assignable to return type int | ||
|
||
return; // Warning: no return expression means default value for int will be returned | ||
si | ||
|
||
test_int_2() -> int => 1234; // OK - correct type | ||
|
||
test_int_3() -> int => "Hello"; // Error: string not assignable to int | ||
|
||
test_void_1() is | ||
return 1234; // Error: any value returned from void function is incorrect | ||
|
||
return; // OK - no value expected | ||
si | ||
return; // OK - no value expected | ||
si | ||
|
||
test_void_2() => 12345; // Eventually would like an omitted return type to be inferred, but it's void for now | ||
test_void_2() => 12345; // Eventually would like an omitted return type to be inferred, but it's void for now | ||
|
||
test_object_1() -> object is | ||
return 1234; // OK - int 1234 is assignable to object | ||
test_object_1() -> object is | ||
return 1234; // OK - int 1234 is assignable to object | ||
|
||
return "Hello"; // OK - string "Hello" is assignable to object | ||
si | ||
return "Hello"; // OK - string "Hello" is assignable to object | ||
si | ||
si | ||
si |
2 changes: 1 addition & 1 deletion
2
integration-tests/semantic/function-return-type-check/warn.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
test.ghul: 24,13..24,19: warn: return without value from non void function returns default value of type Ghul.int | ||
test.ghul: 13,9..13,15: warn: return without value from non void function returns default value of type Ghul.int |
10 changes: 5 additions & 5 deletions
10
integration-tests/semantic/generic-arguments-type-compatibility-1/err.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
integration-tests/semantic/generic-class-arguments-are-objects-1/err.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
test.ghul: 26,16..26,21: error: cannot return value of type T from function of type BLAH | ||
test.ghul: 26,16..26,21: error: cannot return value of type T where BLAH expected | ||
test.ghul: 31,15..31,19: error: member blah not found in T | ||
test.ghul: 36,9..36,21: error: BLAH is not assignable to T |
6 changes: 3 additions & 3 deletions
6
...ests/semantic/generic-function-type-arguments-are-not-compatible-with-null-1/err.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
test.ghul: 10,16..10,20: error: cannot return value of type null from function of type U | ||
test.ghul: 15,9..15,21: error: null is not assignable to T | ||
test.ghul: 18,9..18,21: error: null is not assignable to U | ||
test.ghul: 14,5..14,17: error: null is not assignable to T | ||
test.ghul: 17,5..17,17: error: null is not assignable to U | ||
test.ghul: 9,12..9,16: error: cannot return value of type null where U expected |
34 changes: 16 additions & 18 deletions
34
...n-tests/semantic/generic-function-type-arguments-are-not-compatible-with-null-1/test.ghul
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
namespace Test.GenericFunctionTypeArgumentsAreAssignableFromNull is | ||
use Collections; | ||
use Collections; | ||
|
||
class BLAH is | ||
blah(); | ||
si | ||
class BLAH is | ||
blah(); | ||
si | ||
|
||
to_t[T,U](value: T) -> U is | ||
// expect error: T is not compatible with null | ||
return null; | ||
si | ||
to_t[T,U](value: T) -> U is | ||
// expect error: T is not compatible with null | ||
return null; | ||
si | ||
|
||
set_from_t[T,U](value: T, other: U) is | ||
// expect error: T is not compatible with null | ||
value = null; | ||
set_from_t[T,U](value: T, other: U) is | ||
// expect error: T is not compatible with null | ||
value = null; | ||
|
||
// expect error: U is not compatible with null | ||
other = null; | ||
si | ||
// expect error: U is not compatible with null | ||
other = null; | ||
si | ||
|
||
entry() is | ||
si | ||
si | ||
entry() is | ||
si |
4 changes: 2 additions & 2 deletions
4
...ion-tests/semantic/generic-function-type-arguments-are-not-interchangeable-1/err.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
test.ghul: 11,16..11,21: error: cannot return value of type T from function of type U | ||
test.ghul: 16,9..16,22: error: U is not assignable to T | ||
test.ghul: 14,5..14,18: error: U is not assignable to T | ||
test.ghul: 9,12..9,17: error: cannot return value of type T where U expected |
31 changes: 14 additions & 17 deletions
31
...ration-tests/semantic/generic-function-type-arguments-are-not-interchangeable-1/test.ghul
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
namespace Test.GenericFunctionTypeArgumentsAreObjects is | ||
use Collections; | ||
use Collections; | ||
|
||
class BLAH is | ||
blah(); | ||
si | ||
class BLAH is | ||
blah(); | ||
si | ||
|
||
to_t[T,U](value: T) -> U is | ||
// expect error - T should not be assignable to U | ||
return value; | ||
si | ||
|
||
to_t[T,U](value: T) -> U is | ||
// expect error - T should not be assignable to U | ||
return value; | ||
si | ||
set_from_t[T,U](value: T, other: U) is | ||
// expect error - U should not be assignable to T | ||
value = other; | ||
si | ||
|
||
set_from_t[T,U](value: T, other: U) is | ||
// expect error - U should not be assignable to T | ||
value = other; | ||
si | ||
|
||
entry() is | ||
si | ||
si | ||
entry() is | ||
si |
8 changes: 4 additions & 4 deletions
8
integration-tests/semantic/generic-function-type-arguments-are-objects-1/err.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
test.ghul: 22,13..22,28: error: T is not assignable to Test.GenericFunctionTypeArgumentsAreObjects.BLAH | ||
test.ghul: 25,16..25,21: error: cannot return value of type T from function of type Test.GenericFunctionTypeArgumentsAreObjects.BLAH | ||
test.ghul: 30,15..30,19: error: member blah not found in T | ||
test.ghul: 35,9..35,21: error: Test.GenericFunctionTypeArgumentsAreObjects.BLAH is not assignable to T | ||
test.ghul: 21,9..21,24: error: T is not assignable to BLAH | ||
test.ghul: 24,12..24,17: error: cannot return value of type T where BLAH expected | ||
test.ghul: 29,11..29,15: error: member blah not found in T | ||
test.ghul: 34,5..34,17: error: BLAH is not assignable to T |
76 changes: 37 additions & 39 deletions
76
integration-tests/semantic/generic-function-type-arguments-are-objects-1/test.ghul
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,38 @@ | ||
namespace Test.GenericFunctionTypeArgumentsAreObjects is | ||
use Collections; | ||
|
||
class BLAH is | ||
blah(); | ||
si | ||
|
||
|
||
to_string[T](value: T) -> string is | ||
// expect OK - to_string() is a method on all objects | ||
return value.to_string(); | ||
si | ||
|
||
to_object[T](value: T) -> object is | ||
// expect OK - T should be assignable to object | ||
return value; | ||
si | ||
|
||
// FIXME: this should give an error | ||
to_blah[T](value: T) -> BLAH is | ||
// expect error - T is not assignable to BLAH | ||
let b: BLAH = value; | ||
|
||
// expect error - T is not assignable to BLAH | ||
return value; | ||
si | ||
|
||
do_blah[T](value: T) is | ||
// expect error - T does not have a method called blah | ||
value.blah(); | ||
si | ||
|
||
set_from_blah[T](value: T, blah: BLAH) is | ||
// expect error - BLAH is not assignable to T | ||
value = blah; | ||
si | ||
|
||
entry() is | ||
si | ||
use Collections; | ||
|
||
class BLAH is | ||
blah(); | ||
si | ||
|
||
|
||
to_string[T](value: T) -> string is | ||
// expect OK - to_string() is a method on all objects | ||
return value.to_string(); | ||
si | ||
|
||
to_object[T](value: T) -> object is | ||
// expect OK - T should be assignable to object | ||
return value; | ||
si | ||
|
||
// FIXME: this should give an error | ||
to_blah[T](value: T) -> BLAH is | ||
// expect error - T is not assignable to BLAH | ||
let b: BLAH = value; | ||
|
||
// expect error - T is not assignable to BLAH | ||
return value; | ||
si | ||
|
||
do_blah[T](value: T) is | ||
// expect error - T does not have a method called blah | ||
value.blah(); | ||
si | ||
|
||
set_from_blah[T](value: T, blah: BLAH) is | ||
// expect error - BLAH is not assignable to T | ||
value = blah; | ||
si | ||
|
||
entry() is | ||
si |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
test.ghul: 503,19..503,23: error: cannot return value of type null from function of type T | ||
test.ghul: 510,22..510,26: error: cannot return value of type null from function of type T | ||
test.ghul: 503,19..503,23: error: cannot return value of type null where T expected | ||
test.ghul: 510,22..510,26: error: cannot return value of type null where T expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
test.ghul: 15,22..15,26: error: cannot return value of type null from function of type T | ||
test.ghul: 6,19..6,23: error: cannot return value of type null from function of type T | ||
test.ghul: 15,22..15,26: error: cannot return value of type null where T expected | ||
test.ghul: 6,19..6,23: error: cannot return value of type null where T expected |
Oops, something went wrong.