diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index 67e08f14f411..fb1db920d65b 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -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. */ diff --git a/tests/neg/3559.check b/tests/neg/3559.check new file mode 100644 index 000000000000..d385b1523478 --- /dev/null +++ b/tests/neg/3559.check @@ -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 diff --git a/tests/neg/3559.scala b/tests/neg/3559.scala new file mode 100644 index 000000000000..66eafa8a43f3 --- /dev/null +++ b/tests/neg/3559.scala @@ -0,0 +1,6 @@ +class A(a: Any) { + def this() = { + this(b) // error: forward reference not allowed from self constructor invocation + def b = new {} + } +} diff --git a/tests/neg/3559b.check b/tests/neg/3559b.check new file mode 100644 index 000000000000..a147136e1210 --- /dev/null +++ b/tests/neg/3559b.check @@ -0,0 +1,4 @@ +-- Error: tests/neg/3559b.scala:3:9 ------------------------------------------------------------------------------------ +3 | this(b) // error + | ^ + | b is not accessible from constructor arguments diff --git a/tests/neg/3559b.scala b/tests/neg/3559b.scala new file mode 100644 index 000000000000..7bfbc16dc4d4 --- /dev/null +++ b/tests/neg/3559b.scala @@ -0,0 +1,7 @@ +class A(a: Any) { + def this() = { + this(b) // error + } + + def b = new {} +} diff --git a/tests/neg/3559c.check b/tests/neg/3559c.check new file mode 100644 index 000000000000..0526712e2977 --- /dev/null +++ b/tests/neg/3559c.check @@ -0,0 +1,4 @@ +-- Error: tests/neg/3559c.scala:3:9 ------------------------------------------------------------------------------------ +3 | this(a) // error + | ^ + | a is not accessible from constructor arguments diff --git a/tests/neg/3559c.scala b/tests/neg/3559c.scala new file mode 100644 index 000000000000..de54b3a097ce --- /dev/null +++ b/tests/neg/3559c.scala @@ -0,0 +1,7 @@ +class A(a: Any) { + def this() = { + this(a) // error + } + + def b = new {} +} diff --git a/tests/neg/3559d.check b/tests/neg/3559d.check new file mode 100644 index 000000000000..213f4f165f68 --- /dev/null +++ b/tests/neg/3559d.check @@ -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` diff --git a/tests/neg/3559d.scala b/tests/neg/3559d.scala new file mode 100644 index 000000000000..b4306427ad02 --- /dev/null +++ b/tests/neg/3559d.scala @@ -0,0 +1,9 @@ +class B { + def f: String = "hello" +} + +class A(a: Any) extends B { + def this() = { + this(f) // error + } +}