Skip to content

Commit 2aedbc6

Browse files
Fix backtracking in nested overloads (#1007)
Fixes #996.
1 parent 37c705f commit 2aedbc6

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed

effekt/shared/src/main/scala/effekt/Typer.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ object Typer extends Phase[NameResolved, Typechecked] {
11791179
// use the typer state after this checking pass
11801180
Context.restoreTyperstate(st)
11811181
// reassign symbol of fun to resolved calltarget symbol
1182-
Context.assignSymbol(id, sym)
1182+
Context.annotateSymbol(id, sym)
11831183

11841184
return tpe
11851185

@@ -1607,6 +1607,12 @@ trait TyperOps extends ContextOps { self: Context =>
16071607
}
16081608
}
16091609

1610+
private[typer] def annotateSymbol(id: source.IdRef, sym: symbols.Symbol) =
1611+
annotations.update(Annotations.Symbol, id, sym)
1612+
1613+
override def symbolOption(id: source.Id): Option[Symbol] =
1614+
Context.annotations.get(Annotations.Symbol, id).orElse { super.symbolOption(id) }
1615+
16101616
private[typer] def bind(s: ValueSymbol, tpe: ValueType): Unit =
16111617
annotations.update(Annotations.ValueType, s, tpe)
16121618

@@ -1702,6 +1708,8 @@ trait TyperOps extends ContextOps { self: Context =>
17021708
annotations.updateAndCommit(Annotations.BoundCapabilities) { case (t, caps) => caps }
17031709
annotations.updateAndCommit(Annotations.CapabilityArguments) { case (t, caps) => caps }
17041710
annotations.updateAndCommit(Annotations.CapabilityReceiver) { case (t, caps) => caps }
1711+
1712+
annotations.updateAndCommit(Annotations.Symbol) { case (t, sym) => sym }
17051713
}
17061714

17071715
//</editor-fold>

effekt/shared/src/main/scala/effekt/context/Annotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ trait TreeAnnotations { self: Context =>
467467
// addDefinedSymbolToSource(sym)
468468
}
469469

470-
def symbolOf(id: source.Id): Symbol = symbolOption(id) getOrElse {
470+
def symbolOf(id: source.Id): Symbol = this.symbolOption(id) getOrElse {
471471
panic(s"Internal Compiler Error: Cannot find symbol for ${id}")
472472
}
473473
def symbolOption(id: source.Id): Option[Symbol] =

examples/pos/imports.effekt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module imports
33
import examples/pos/lists
44

55
def main() = {
6-
val l = Cons(1, Cons(2, Nil()));
6+
val l: lists::List[Int] = Cons(1, Cons(2, Nil()));
77
foreach(l) { el => println(el) };
88
()
99
}

examples/pos/issue996.check

Whitespace-only changes.

examples/pos/issue996.effekt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
extern type BitArray
2+
type IntArray = Unit
3+
4+
def nums(): IntArray = ()
5+
6+
def for(arr: BitArray) { action: Byte => Unit }: Unit = ()
7+
def for(arr: IntArray) { action: Int => Unit }: Unit = ()
8+
9+
def print(b: Byte) = println(b)
10+
def print(i: Int) = println(i)
11+
12+
def main() = {
13+
val arr: IntArray = nums()
14+
arr.for { x =>
15+
print(x)
16+
}
17+
}

examples/pos/lists.effekt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ type List[A] {
44
Nil();
55
Cons(head: A, tail: List[A])
66
}
7-
7+
namespace lists {
8+
type List[A] = List[A]
9+
}
810

911
def map[A, B](l: List[A]) { f: A => B } : List[B] =
1012
l match {

0 commit comments

Comments
 (0)