diff --git a/test/checker/if_part_test_is_bool.bolt b/test/checker/if_part_test_is_bool.bolt new file mode 100644 index 000000000..ee660020a --- /dev/null +++ b/test/checker/if_part_test_is_bool.bolt @@ -0,0 +1,8 @@ + +@expect_diagnostic 2010 +if 1. + True + +@expect_diagnostic 2010 +if "a". + False diff --git a/test/checker/instance_arguments_type_classes.bolt.disabled b/test/checker/instance_arguments_type_classes.bolt.disabled new file mode 100644 index 000000000..39c23789b --- /dev/null +++ b/test/checker/instance_arguments_type_classes.bolt.disabled @@ -0,0 +1,36 @@ + +# Advanced test for instance arguments as type classses +# From the paper 'On the Bright Side of Type Classes' + +# Representation of the type class +struct Eq a. + equal: a -> a -> Bool + +let primBoolEq a b = match (a, b). + (True, True) => True + (False, False) => True + _ => False + +# Class Eq default method +let equal {{ eqT : Eq a }} : {{ Eq a }} -> a -> a -> Bool = eqT.equal + +# Instance Eq Bool +let eqBool : Eq Bool = Eq { + equal = primBoolEq +} + +# Instance Eq (List a) +let primListEq a b = match (a, b). + ([], []) => True + (_, []) => False + ([], _) => False + (a :: b, c :: d) => equal a c && primListEq b c + +# Instance Eq a => Eq List a +let listEq : Eq a -> Eq (List a) = Eq { + equal = primListEq +} + + equal True False + equal 1 2 + equal 1 False diff --git a/test/checker/mutual_recursion_is_odd_is_even.bolt b/test/checker/mutual_recursion_is_odd_is_even.bolt new file mode 100644 index 000000000..8ddbac8af --- /dev/null +++ b/test/checker/mutual_recursion_is_odd_is_even.bolt @@ -0,0 +1,17 @@ + +# Mutually recusive functions + +let is_odd x. + if x == 1. + return True + else. + return is_even (x-1) + +let is_even x. + if x == 0. + return True + else. + return is_odd (x-1) + +@:Bool is_even 1 + diff --git a/test/checker/nested_vars_reaching_parent_scope.bolt b/test/checker/nested_vars_reaching_parent_scope.bolt new file mode 100644 index 000000000..602f1a243 --- /dev/null +++ b/test/checker/nested_vars_reaching_parent_scope.bolt @@ -0,0 +1,12 @@ + +# Testing whether nested variable declarations work + +let id x. + let foo = x + return foo + +@:Int id 1 +@:Bool id True +@:Int id 1 +@:String id "foo" + diff --git a/test/checker/pattern_matching_variant.bolt b/test/checker/pattern_matching_variant.bolt new file mode 100644 index 000000000..d1acf88a5 --- /dev/null +++ b/test/checker/pattern_matching_variant.bolt @@ -0,0 +1,13 @@ + +enum MyList a. + Nil + Pair a (MyList a) + +let (Pair True Nil) : MyList Bool +let (Pair "foo" Nil) : MyList String + +@expect_diagnostic 2010 +let (Pair 1 Nil) : MyList Bool + +let Nil : MyList a + diff --git a/test/checker/simple_instance_arguments.bolt.disabled b/test/checker/simple_instance_arguments.bolt.disabled new file mode 100644 index 000000000..a0c7962cb --- /dev/null +++ b/test/checker/simple_instance_arguments.bolt.disabled @@ -0,0 +1,10 @@ + +# Simple test for instance arguments + +implicit let theanswer = 1 + +let is_answer {{ a : Int }} x = a == x + +is_answer 1 +is_answer 2 +is_answer 42 diff --git a/test/checker/simple_tuple_test.bolt b/test/checker/simple_tuple_test.bolt new file mode 100644 index 000000000..6018effee --- /dev/null +++ b/test/checker/simple_tuple_test.bolt @@ -0,0 +1,16 @@ + + +let pair x y = (x, y) + +let p1 = pair 1 1 +let p2 = (1, True) +let p3 = (False, 1) + +@:Int p1.0 +@:Int p1.1 + +@:Int p2.0 +@:Bool p2.1 + +@:Bool p3.0 +@:Int p3.1 diff --git a/test/checker/test_equality_tapp.bolt b/test/checker/test_equality_tapp.bolt new file mode 100644 index 000000000..d7611b84c --- /dev/null +++ b/test/checker/test_equality_tapp.bolt @@ -0,0 +1,10 @@ + +enum List a. + Nil + Pair a (List a) + +let x : List Int +@expect_diagnostic 2010 +let y : List Bool = x +let z : List String + diff --git a/test/checker/test_qualified_type_sigs.bolt b/test/checker/test_qualified_type_sigs.bolt new file mode 100644 index 000000000..0349492b4 --- /dev/null +++ b/test/checker/test_qualified_type_sigs.bolt @@ -0,0 +1,24 @@ + + +class Eq a. + let eq : a -> a -> Bool + +class Show a. + let show : a -> String + +instance Eq String. + let eq a b = True + +instance Show Bool. + let show s = "a boolean" + +instance Show Int. + let show s = "a string" + +let repr_eq_1 x y : (Show a, Show b) => a -> b -> Bool = eq (show x) (show y) + +@expect_diagnostic 2201 +let repr_eq_2 x y : (Show b) => a -> b -> Bool = eq (show x) (show y) + +@expect_diagnostic 2201 +let repr_eq_3 x y : a -> b -> Bool = eq (show x) (show y) diff --git a/test/checker/variable_mistyping.bolt b/test/checker/variable_mistyping.bolt new file mode 100644 index 000000000..b8757cf35 --- /dev/null +++ b/test/checker/variable_mistyping.bolt @@ -0,0 +1,6 @@ + +# Testing variable typing + +@expect_diagnostic 2010 +let a: Int = "foo" + diff --git a/test/checker/wrong_return_type.bolt b/test/checker/wrong_return_type.bolt new file mode 100644 index 000000000..ddfb52b21 --- /dev/null +++ b/test/checker/wrong_return_type.bolt @@ -0,0 +1,11 @@ + +let wrong x. + if True. + return 1 + elif False. + return 2 + else. + @expect_diagnostic 2010 + return "foo" + +wrong 1