-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce generic Array type * Simplify handling of Failable types
- Loading branch information
Showing
8 changed files
with
160 additions
and
20 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
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
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Output | ||
// 1 2 3 | ||
// Hello Hi | ||
|
||
fun test(arr: []): Null { | ||
echo arr | ||
} | ||
|
||
test([1, 2, 3]) | ||
test(["Hello", "Hi"]) |
10 changes: 10 additions & 0 deletions
10
src/tests/validity/generic_array_in_argument_and_return.ab
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Output | ||
// 1 2 3 | ||
// Hello Hi | ||
|
||
fun test(arr: []): [] { | ||
return arr | ||
} | ||
|
||
echo test([1, 2, 3]) | ||
echo test(["Hello", "Hi"]) |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Output | ||
// 1 2 3 | ||
|
||
fun test(arr: [Num]): []? { | ||
if false { fail 1 } | ||
return arr | ||
} | ||
|
||
echo unsafe test([1, 2, 3]) |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Output | ||
// 1 2 3 | ||
|
||
fun test(arr: [Num]): [] { | ||
return arr | ||
} | ||
|
||
echo test([1, 2, 3]) |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Output | ||
// Generic | ||
// Number | ||
// Text | ||
|
||
fun return_generic(): [] { | ||
return ["the great unknown"] | ||
} | ||
|
||
fun test(arr: []) { | ||
if arr is [] { | ||
echo "Generic" | ||
} | ||
|
||
if arr is [Num] { | ||
echo "Number" | ||
} | ||
|
||
if arr is [Text] { | ||
echo "Text" | ||
} | ||
} | ||
|
||
test(return_generic()) | ||
test([42, 69]) | ||
test(["Hello", "Hi"]) |