Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #292: adding tuple in hasSameKind function in Type.hs #296

Merged
merged 4 commits into from
Dec 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions src/tests/encore/basic/maybeTuple.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
--
-- Test match executes the catch all statement first
--
def test_catch_all(z: Maybe (int,int)): String
match z with
z => "catchall"
Just (32,32) => "Error, general condition should have been catched first"

--
-- Test match executes the specific val statement
--
def test_catch_specific_val(x: Maybe (int,int)): String
match x with
Just (32,32) => "32,32"
z => "error, should catch specific value"

--
-- Test all branches of the match expression
-- More related to typechecking than the actual result
--
def test_match_decl(): void
match Just(Just (32,32)) with
Nothing => print "nothing"
Just(z) => print "just z"
Just(Nothing) => print "just nothing"
Just(Just z) => print "just just z"
Just(Just (0,0)) => print "just just (zero,zero)"
z => ()

--
-- Test matching on objects
--
def test_match_on_object(o: Main): Maybe Main
match (Just o) with
Just z => Just o
z => Nothing : Maybe Main

--
-- Test precedence of the match expression; write the general cases at the end
-- since it follows sequential order
--
def test_precedence_of_match(): void
match Just(Just((32,32))) with
Nothing => print "nothing"
Just(Nothing) => print "just nothing"
Just(Just z) => print "just just z"
Just(Just((0,0))) => print "just just (zero,zero)"
Just(z) => print "just z"
z => print "catch all"

--
-- Test a match clause that has Nothing as the main argument
--
def test_match_nothing_decl() : void
match (Nothing : Maybe (int,int)) with
Just z => print "12,12"
Just (12,12) => print "23,23"
Just (0,0) => print "0,0"
Nothing => print "Nothing"

--
-- Test that we can pass arguments and return a value of Option type
--
def test_pass_args_and_return_of_maybe(): Maybe (int,int)
match Just((32,32)) with
Just(z) => { print "Just(z)"; Just(z) }
Nothing => { print "Nothing"; Nothing : Maybe (int,int) }

--
-- Test unification of the last expression
--
def test_unification_last_expression() : Maybe (int,int)
Nothing

--
-- Test multiple assignments and changes between them
--
def test_multiple_assignments(x: Maybe (int,int)) : (int,int) {
let y = Nothing : Maybe (int,int)
z = Just((32,32))
in {
x = y;
y = (Just (23,23));
y = x;
y = z;
x = Nothing : Maybe (int,int);
y;
match x with {
Just(z) => (23,23)
Nothing => (34,34)
}
}
}

passive class Poly<t> {
def morphic(x: t): Maybe t {
Just x
}
}

class Main
def main(): void
let
x = Just((32,32))
poly = new Poly<(int,int)>
-- u = foo(Just (32,32))
in {
print test_catch_all(x);
print test_catch_specific_val(x);
test_match_decl();
test_match_on_object(this);
test_precedence_of_match();
test_match_nothing_decl();
test_pass_args_and_return_of_maybe();
test_unification_last_expression();
test_multiple_assignments(x);
match poly.morphic((32,32)) with
Just (y,z) => print ("{},{}\n",y,z)
Nothing => print "0,0"
;
}
7 changes: 7 additions & 0 deletions src/tests/encore/basic/maybeTuple.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
catchall
32,32
just z
just just z
Nothing
Just(z)
32,32
1 change: 1 addition & 0 deletions src/types/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ hasSameKind ty1 ty2
areBoth isStreamType = getResultType ty1 `hasSameKind` getResultType ty2
| (isBottomTy1 || isBottomTy2) && not (areBoth isBottomType) = True -- xor
| areBoth isPrimitive ||
areBoth isTupleType ||
areBoth isTypeVar ||
areBoth isRefType ||
areBoth isArrowType = True
Expand Down