Skip to content

Commit 8ee0ec5

Browse files
committed
Fix #3559: fix scope for typing this(...) in 2nd constructor
The scope for typing `this(...)` should include both constructor params and local defs. The latter are included to provide more friendly error messages for references to local definitions.
1 parent d7896b5 commit 8ee0ec5

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ object Contexts {
381381
superOrThisCallContext(owner, constrCtx.scope)
382382
.setTyperState(typerState)
383383
.setGadt(gadt)
384+
.fresh
385+
.setScope(this.scope)
384386
}
385387

386388
/** The super- or this-call context with given owner and locals. */

tests/neg/3559.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg/3559.scala:3:9 -------------------------------------------------------------------------------------
2+
3 | this(b) // error: forward reference not allowed from self constructor invocation
3+
| ^
4+
| forward reference not allowed from self constructor invocation

tests/neg/3559.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class A(a: Any) {
2+
def this() = {
3+
this(b) // error: forward reference not allowed from self constructor invocation
4+
def b = new {}
5+
}
6+
}

0 commit comments

Comments
 (0)