-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 #15737 from dotty-staging/fix-15723
Fix treatment of parameter selections via this in constructors.
- Loading branch information
Showing
6 changed files
with
88 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
import language.experimental.fewerBraces | ||
|
||
object Test: | ||
def Test = | ||
|
||
val xo: Option[Int] = Some(1) | ||
|
||
val y = | ||
xo.fold: | ||
22 | ||
.apply: x => | ||
x + 1 | ||
println(y) | ||
|
||
assert((new Object: Any).isInstanceOf[Object]) |
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,2 @@ | ||
20 | ||
20 |
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,10 @@ | ||
class B(val y: Int) { | ||
println(this.y) | ||
foo() | ||
def foo() = println(this.y) | ||
} | ||
class C(override val y: Int) extends B(10) | ||
|
||
object Test extends App { | ||
new C(20) | ||
} |
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 @@ | ||
Bob is 22 years old and lives in Paris | ||
Hello Peter | ||
Bob is 22 years old and lives in Paris | ||
Hello PersonExtractor(Peter) |
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,45 @@ | ||
object Test1: | ||
class User(val name: String, val age: Int, val city: String) | ||
object User: | ||
def unapply(user: User) = UserExtractor(user.name, user.age, user.city) | ||
|
||
case class UserExtractor(name: String, age: Int, city: String) | ||
|
||
class Person(val name: String) | ||
object Person: | ||
def unapply(person: Person) = PersonExtractor(person.name) | ||
|
||
case class PersonExtractor(name: String) | ||
|
||
def test = | ||
val user = User("Bob", 22, "Paris") | ||
(user: Any) match | ||
case User(name, age, city) => println(s"$name is $age years old and lives in $city") | ||
val p = Person("Peter") | ||
(p: Any) match | ||
case Person(n) => println(s"Hello $n") | ||
|
||
object Test2: | ||
class User(val name: String, val age: Int, val city: String) | ||
object User: | ||
def unapply(user: User): Option[UserExtractor] = Some(UserExtractor(user.name, user.age, user.city)) | ||
|
||
case class UserExtractor(name: String, age: Int, city: String) | ||
|
||
class Person(val name: String) | ||
object Person: | ||
def unapply(person: Person): Some[PersonExtractor] = Some(PersonExtractor(person.name)) | ||
|
||
case class PersonExtractor(name: String) | ||
|
||
def test = | ||
val user = User("Bob", 22, "Paris") | ||
(user: Any) match | ||
case User(name, age, city) => println(s"$name is $age years old and lives in $city") | ||
val p = Person("Peter") | ||
(p: Any) match | ||
case Person(n) => println(s"Hello $n") | ||
|
||
@main def Test = | ||
Test1.test | ||
Test2.test |