Skip to content

Fix #3559: fix scope for typing this(...) in 2nd constructor #7200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ object Contexts {
superOrThisCallContext(owner, constrCtx.scope)
.setTyperState(typerState)
.setGadt(gadt)
.fresh
.setScope(this.scope)
}

/** The super- or this-call context with given owner and locals. */
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/3559.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/3559.scala:3:9 -------------------------------------------------------------------------------------
3 | this(b) // error: forward reference not allowed from self constructor invocation
| ^
| forward reference not allowed from self constructor invocation
6 changes: 6 additions & 0 deletions tests/neg/3559.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class A(a: Any) {
def this() = {
this(b) // error: forward reference not allowed from self constructor invocation
def b = new {}
}
}
4 changes: 4 additions & 0 deletions tests/neg/3559b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/3559b.scala:3:9 ------------------------------------------------------------------------------------
3 | this(b) // error
| ^
| b is not accessible from constructor arguments
7 changes: 7 additions & 0 deletions tests/neg/3559b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class A(a: Any) {
def this() = {
this(b) // error
}

def b = new {}
}
4 changes: 4 additions & 0 deletions tests/neg/3559c.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/3559c.scala:3:9 ------------------------------------------------------------------------------------
3 | this(a) // error
| ^
| a is not accessible from constructor arguments
7 changes: 7 additions & 0 deletions tests/neg/3559c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class A(a: Any) {
def this() = {
this(a) // error
}

def b = new {}
}
6 changes: 6 additions & 0 deletions tests/neg/3559d.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- [E006] Unbound Identifier Error: tests/neg/3559d.scala:7:9 ----------------------------------------------------------
7 | this(f) // error
| ^
| Not found: f

longer explanation available when compiling with `-explain`
9 changes: 9 additions & 0 deletions tests/neg/3559d.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class B {
def f: String = "hello"
}

class A(a: Any) extends B {
def this() = {
this(f) // error
}
}