Skip to content

Commit

Permalink
Adds some test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
MattisKra committed Sep 15, 2023
1 parent 4063ed1 commit 7f8b7cf
Show file tree
Hide file tree
Showing 32 changed files with 284 additions and 2 deletions.
6 changes: 4 additions & 2 deletions effekt/shared/src/main/scala/effekt/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ object Typer extends Phase[NameResolved, Typechecked] {
val a = checkExprAsBlock(e, None)
val Result(tpe, funEffs) = a match {
case Result(b: FunctionType, capt) => Result(b, capt)
case Result(b @ BlockTypeRef(BlockTypeWildcard(_)), capt) => Result(b, capt)
case Result(b: BlockTypeRef, capt) => Result(b, capt)
case _ =>
Context.abort("Cannot infer function type for callee.")
}

val Result(t, eff) = tpe match {
case b: FunctionType =>
checkCallTo(c, "function", b, targs map { _.resolve }, vargs, bargs, expected)
case b @ BlockTypeRef(BlockTypeWildcard(_)) =>
case b: BlockTypeRef =>
val sym = e match {
case source.Var(id: source.IdRef) => Some(id.symbol)
case source.Assign(id: source.IdRef, expr) => Some(id.symbol)
Expand Down Expand Up @@ -788,6 +788,8 @@ object Typer extends Phase[NameResolved, Typechecked] {
matchExpected(funType, funTypeWithWildcard)

funType

case _ => sys error "Shouldn't happen"
}

Result(funType, Pure)
Expand Down
16 changes: 16 additions & 0 deletions examples/pts/boxAndRun.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def f(x: Int): Int = x + 1

def runAndBox{func: _}: (Int, _) = {
val a = func(1)
val b = box Func
(a, b)
}

def main() = {
val a: Int = runAndBox{f}
1
}




11 changes: 11 additions & 0 deletions examples/pts/defWithEff.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
effect Eff(): Unit

def run{func: _} = {
val a: Int = func(1)
def b: Int => Int / Eff = func
1
}

def main() = {
()
}
11 changes: 11 additions & 0 deletions examples/pts/defWithTypeParam.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def run{func: _} = {
val a: Int = func(1)
def b: A => Int = func
1
}

def main() = {
()
}

// Should NOT work
16 changes: 16 additions & 0 deletions examples/pts/effectHandling.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
effect Eff(): Unit

def run{x: _}: Int = {
def y: Int => Int / Eff = x
x(1)
}

def func(x: Int): Int / Eff = {
do Eff()
1
}

def main() = {
run{ func }
1
}
6 changes: 6 additions & 0 deletions examples/pts/example.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def f(x: Int): _ = g(x)
def g(x: Int): _ = f(x)

def main() = {
()
}
5 changes: 5 additions & 0 deletions examples/pts/externResource.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extern resource test: _

def main() = {
()
}
9 changes: 9 additions & 0 deletions examples/pts/functionDoubleUse.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def run{func: _ } = {
val a: Int = func(1)
val b = func(2)
func(3)
}

def main() = {
()
}
10 changes: 10 additions & 0 deletions examples/pts/functionReturnType.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def run(x: _){func: _} = {
val a = func(x, 1)
val b: Int = func(x, 1)
val c: Int = x
1
}

def main() = {
run("a"){ (x: String, y: Int) => x }
}
8 changes: 8 additions & 0 deletions examples/pts/overloaded.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def f(x: Int): Int = 1

def f(x: Int): String = "2"

def main() = {
val a: _ = f(1)
1
}
5 changes: 5 additions & 0 deletions examples/pts/recursion.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def f(x: _, y: Int): Int =
if(y > 0)
f(x, y - 1)
else
0
9 changes: 9 additions & 0 deletions examples/pts/test10.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// opClause wildcard

effect Test {
def output(x: Int): Int / _
}

def main() = {
()
}
13 changes: 13 additions & 0 deletions examples/pts/test11.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Parametric Captures

effect Eff[A]{ def output(): Int }

def f{ eff: Eff[Int] } = {
val a = fun() { eff.output() }
val b: _ = a
1
}

def main() = {
()
}
6 changes: 6 additions & 0 deletions examples/pts/test12.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Wildcards in anonymous functions

def main() = {


}
26 changes: 26 additions & 0 deletions examples/pts/test14.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
effect Eff { def use(): Unit }

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

val f: () => Unit at _ = x;
val g: _ at _ = x
val h: _ = x

def m(x: Int => Int at {eff}): Int = {
println("called")
1
}

def n: _ = m
def o: Int => Int = n

f
}



def main() = {
()
}
5 changes: 5 additions & 0 deletions examples/pts/test16.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extern _ def func(x: Int): Int = "test"

def main() = {
()
}
5 changes: 5 additions & 0 deletions examples/pts/test17.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extern def func(x: _): _ / _ = "Test"

def main() = {
()
}
5 changes: 5 additions & 0 deletions examples/pts/test18.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
val res = fun(x: _) { 1 }

def main() = {
println(res(1))
}
7 changes: 7 additions & 0 deletions examples/pts/test19.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def run{ f: Int => Int / _ }: Int = f(1)

val res = run{ (x: Int) => x + 1 }

def main() = {
println(res)
}
5 changes: 5 additions & 0 deletions examples/pts/test20.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def identity[A](x: A): A = x

def runFunc{block: _}: Int = block(1)

def main() = { runFunc{identity} }
9 changes: 9 additions & 0 deletions examples/pts/test21.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def id(x: Int): Int = x

def id(x: String): String = x

def main() = {
val a = id(1)
val b = id("a")
println(a)
}
9 changes: 9 additions & 0 deletions examples/pts/test22.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def func(x: Int): _ =
if(x == 0)
1
else
func(x - 1) + 1

def main() = {
println(func(1))
}
17 changes: 17 additions & 0 deletions examples/pts/test23.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
effect Eff(): Unit

def run{x: _}: Int = {
val a: Int = x(1)
//def y: Int => Int / Eff = x
1
}

def func(x: Int): Int / Eff = {
do Eff()
1
}

def main() = {
run{ func }
1
}
12 changes: 12 additions & 0 deletions examples/pts/test24.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def runFunc[A](x: A){func: _}: Int = {
func(x)
}

def f(x: Int): Int = x + 1

def g(x: String): Int = 1

def main() = {
println(runFunc(1){f})
println(runFunc("a"){g})
}
5 changes: 5 additions & 0 deletions examples/pts/test25.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def f[_](x: Int): Int = x + 1

def main() = {
f(1)
}
5 changes: 5 additions & 0 deletions examples/pts/test26.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extern resource test: Int => Int

def main() = {
()
}
8 changes: 8 additions & 0 deletions examples/pts/test27.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type A = _

val b: A = 1
val c: A = "a"

def main() = {
()
}
10 changes: 10 additions & 0 deletions examples/pts/test28.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def f(x: Int): _ = {
if(x == 0)
"a"
else
f(x - 1) + 1
}

def main() = {
()
}
7 changes: 7 additions & 0 deletions examples/pts/test29.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type A = _

def main() = {
val x: A = 5
val y: A = "a"
1
}
5 changes: 5 additions & 0 deletions examples/pts/testExternDef.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extern def test(x: Int): Int / _ = "test"

def main() = {
()
}
8 changes: 8 additions & 0 deletions examples/pts/twoWildcards.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def f(x: _): Int = {
val y: _ = x
y
}

def main() = {
f("1")
}
7 changes: 7 additions & 0 deletions examples/pts/typeAlias.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type AA = _

def f(x: AA) = 1

def main() = {
1
}

0 comments on commit 7f8b7cf

Please sign in to comment.