Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #735 from retronym/ticket/4842-2
SI-4842 Forbid access to in-construction this in self-constructor args
- Loading branch information
Showing
7 changed files
with
94 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
t4842a.scala:2: error: self constructor arguments cannot reference unconstructed `this` | ||
def this(x: Int) = this(new { println(Foo.this)}) // error | ||
^ | ||
one error found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Foo (x: AnyRef) { | ||
def this(x: Int) = this(new { println(Foo.this)}) // error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
t4842b.scala:2: error: self constructor arguments cannot reference unconstructed `this` | ||
def this() = { this(???)(new { println(TypeArg.this.x) } ); println("next") } // error | ||
^ | ||
one error found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class TypeArg[X](val x: X)(a: AnyRef) { | ||
def this() = { this(???)(new { println(TypeArg.this.x) } ); println("next") } // error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Foo (x: AnyRef) { | ||
def this() = { | ||
this(new { } ) // okay | ||
} | ||
} | ||
|
||
|
||
class Blerg (x: AnyRef) { | ||
def this() = { | ||
this(new { class Bar { println(Bar.this); new { println(Bar.this) } }; new Bar } ) // okay | ||
} | ||
} | ||
|
||
|
||
class Outer { | ||
class Inner (x: AnyRef) { | ||
def this() = { | ||
this(new { class Bar { println(Bar.this); new { println(Bar.this) } }; new Bar } ) // okay | ||
} | ||
|
||
def this(x: Boolean) = { | ||
this(new { println(Outer.this) } ) // okay | ||
} | ||
} | ||
} | ||
|