Skip to content

Commit

Permalink
Merge pull request #5191 from lochana-chathura/fix-bbe
Browse files Browse the repository at this point in the history
[Master] Fix list subtyping BBE output
  • Loading branch information
lochana-chathura authored Feb 12, 2024
2 parents b58e728 + 939eff2 commit 63708aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@
"name": "List subtyping",
"url": "list-subtyping",
"verifyBuild": true,
"verifyOutput": false,
"verifyOutput": true,
"isLearnByExample": true
},
{
Expand Down
15 changes: 8 additions & 7 deletions examples/list-subtyping/list_subtyping.bal
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ import ballerina/io;

public function main() {
int[3] numbers = [144, 232, 322];
// `numbers`, of type `int[3]`, will be a subtype of `int[]`
// since `T[n]` is a subtype of `T[]`
io:println(numbers is int[]);

byte[3] numbers2 = [1, 2, 3];
// `numbers2` will be a subtype of `int[3]`
// `numbers2`, of type byte[3], will be a subtype of `int[3]`
// since `byte` is a subtype of `int` and lengths are the same
io:println(numbers2 is int[3]);

// `numbers2` will be a subtype of `int[]`
// since `byte` is a subtype of `int` and `T[n]` is a sub type of `T[]`
// `numbers2`, of type byte[3], will be a subtype of `int[]`
// since `byte` is a subtype of `int` and `T[n]` is a subtype of `T[]`
io:println(numbers2 is int[]);

[byte, string] person = [1, "Mike"];
// `[byte, string]` is a sub type of `[int, anydata]`
// `[byte, string]` is a subtype of `[int, anydata]`
io:println(person is [int, anydata]);

// `[byte, string]` is a sub type of `[int, anydata...]`
// `[byte, string]` is a subtype of `[int, anydata...]`
io:println(person is [int, anydata...]);

// `int[3]` is a sub type of `[int, anydata...]`
// `int[3]` is a subtype of `[int, anydata...]`
io:println(numbers is [int, anydata...]);
}

12 changes: 7 additions & 5 deletions examples/list-subtyping/list_subtyping.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
$ bal run list_sub_typing.bal
[0,0,0]
[false]
["John","Mike",""]
[["carrot","apple"],["avocado","egg"],["",""]]
$ bal run list_subtyping.bal
true
true
true
true
true
true

0 comments on commit 63708aa

Please sign in to comment.