Skip to content

Commit

Permalink
First work on capture test
Browse files Browse the repository at this point in the history
  • Loading branch information
MattisKra committed Jul 10, 2023
1 parent 70e3861 commit 2cc55be
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 17 deletions.
34 changes: 30 additions & 4 deletions effekt/jvm/src/test/scala/effekt/TyperTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ abstract class AbstractTyperTests extends munit.FunSuite {

given C: Context = compiler.context

val mod = Frontend(src).map(_.mod)
val frontend = Frontend(src)
val mod = frontend.map(_.mod)
assert(mod.isDefined, "Running the frontend succeeds")
compiler.compileSource(src, configs)
val ctx = compiler.context
Expand Down Expand Up @@ -58,18 +59,43 @@ abstract class AbstractTyperTests extends munit.FunSuite {
assertNoDiff(symbols.TypePrinter.show(got), expected, clue)
}

def assertCaptureType(name: String, expected: String, clue: => Any = "capture types don't match"): Unit = {
val syms = C.module.terms(name)
assert(syms.size == 1, s"There is a unique symbol named '${name}'.")
val sym = syms.head
assert(sym.isInstanceOf[symbols.Captures], s"${sym} is a capture symbol.")
val got = C.annotation(Annotations.Captures, sym.asInstanceOf[symbols.BlockSymbol])
assertNoDiff(symbols.TypePrinter.show(got), expected, clue)
}

// TODO further assertions (e.g. for captures etc) on the context
}

}
class TyperTests extends AbstractTyperTests {

testTyper("Simple example test")(
"""type A{}
|def foo(x: A) = x
"""val a : _ = 1
|""".stripMargin
){ C =>
C.assertBlockType("foo", "A => A")
C.assertBlockType("a", "Int")
}

testTyperFile("File test")("examples/pts/typerTest.effekt"){
C => C.assertValueType("a", "Int")
}

testTyperFile("Value type test")("examples/pts/valueType.effekt"){
C => C.assertValueType("num1", "Int")
}

// // Expected an expression, but got a block. in line 12, 28
// testTyperFile("Simple capture test")("examples/pts/capture2.effekt"){
// C => C.assertCaptureType("result", "() => Unit at { eff1 }")
// }

testTyperFile("Nested types test")("examples/pts/nestedTypes.effekt"){
C => C.assertValueType("map1", "Map[Int, String]")
}

}
1 change: 1 addition & 0 deletions effekt/shared/src/main/scala/effekt/Phase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ trait Phase[-In, +Out] { curr =>
run(input)
} catch {
case FatalPhaseError(msg) =>
println(msg)
C.report(msg)
None
}
Expand Down
14 changes: 14 additions & 0 deletions examples/pts/capture2.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
effect Eff { def use(): Unit }

def myModule { eff : Eff } = {
val e = fun() { eff.use(); () };
def x = unbox e;
def test1b = x;

// val f: () => Unit at { _ } = test1b; // THIS IS WRONG: Wildcard is applied with annotating " _ ", not " { _ } "
val f: () => Unit at _ = test1b;

f
}

val result = try { myModule { e } } with e: Eff { def use() = resume(()) }
11 changes: 4 additions & 7 deletions examples/pts/nestedTypes.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ type Map[A, B] {
Map(keys : List[A], values : List[B])
}

def main() = {
val listA : List[_] = Cons(1, Cons(2, Cons(3, Nil())))
val listB : List[_] = Cons("a", Cons("b", Cons("c", Nil())))

val map1 : Map[_, _] = Map(listA, listB)
val map2 : Map[String, Int] = map1
println("end")
}
val listA : List[_] = Cons(1, Cons(2, Cons(3, Nil())))
val listB : List[_] = Cons("a", Cons("b", Cons("c", Nil())))

val map1 : Map[_, _] = Map(listA, listB)
4 changes: 4 additions & 0 deletions examples/pts/typerTest.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def test() = {
val a : _ = 1
a
}
Empty file removed examples/pts/valueType.check
Empty file.
7 changes: 1 addition & 6 deletions examples/pts/valueType.effekt
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
module examples/pts/valueType

def main() = {
val num1 : _ = 1
val num2 : String = num1
println(num1)
}
val num1 : _ = 1

0 comments on commit 2cc55be

Please sign in to comment.