-
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.
Support implicit arguments before extractor method (#18671)
Currently the global object initialization checker crashes when encountering implicit arguments in extractor methods that are before scrutinee. This PR fixes the issue and adds tests with implicit arguments before scrutinee for `unapply` and `unapplySeq` respectively.
- Loading branch information
Showing
9 changed files
with
114 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
object Bar { | ||
class Foo { | ||
def m1(i: Int) = i+1 | ||
def m2(i: Int) = i+2 | ||
} | ||
def unapply(using f1: Foo)(i: Int): Option[Int] = | ||
if i == 0 then Some(f1.m1(i)) else Some(f1.m2(i)) | ||
|
||
given Foo = new Foo | ||
val i1: Int = 0 | ||
val i2: Int = i2 match // error | ||
case Bar(i) => i | ||
case _ => 0 | ||
} |
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,14 @@ | ||
object Bar { | ||
class Foo { | ||
def m1(i: Int) = i+1 | ||
def m2(i: Int) = i+2 | ||
} | ||
def unapply(using f1: Foo)(i: Int): Option[Int] = | ||
if i == 0 then Some(f1.m1(i1)) else Some(f1.m2(i2)) // error | ||
|
||
given Foo = new Foo | ||
val i1: Int = 0 | ||
val i2: Int = i1 match | ||
case Bar(i) => i | ||
case _ => 0 | ||
} |
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,14 @@ | ||
object Bar { | ||
class Foo { | ||
def m1(i: Int) = i + i1 | ||
def m2(i: Int) = i + i2 // error | ||
} | ||
def unapply(using f1: Foo)(i: Int): Option[Int] = | ||
if i == 0 then Some(f1.m1(i)) else Some(f1.m2(i)) | ||
|
||
given Foo = new Foo | ||
val i1: Int = 0 | ||
val i2: Int = i1 match | ||
case Bar(i) => i | ||
case _ => 0 | ||
} |
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,14 @@ | ||
object Bar { | ||
class Foo { | ||
def m1(seq: Seq[Int]) = 1 +: seq | ||
def m2(seq: Seq[Int]) = 2 +: seq | ||
} | ||
def unapplySeq(using f1: Foo)(seqi: Seq[Int]): Option[Seq[Int]] = | ||
if seqi(0) == 0 then Some(f1.m1(seqi)) else Some(f1.m2(seqi)) | ||
|
||
given Foo = new Foo | ||
val i1: Int = 0 | ||
val i2: Int = Seq(i2) match // error | ||
case Bar(i) => i | ||
case _ => 0 | ||
} |
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 @@ | ||
object Bar { | ||
class Foo | ||
def unapplySeq(using f1: Foo)(using f2: Foo)(seqi: Seq[Int])(using Foo): Option[Seq[Int]] = | ||
Some(i1 +: seqi) // error | ||
given Foo = new Foo | ||
val i1: Int = Seq(0) match { | ||
case Bar(i) => i | ||
case _ => 0 | ||
} | ||
} |
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,12 @@ | ||
object Bar { | ||
class Foo { | ||
def m(seq: Seq[Int]) = i1 +: seq // error | ||
} | ||
def unapplySeq(using f1: Foo)(seqi: Seq[Int])(using Foo): Option[Seq[Int]] = | ||
Some(f1.m(seqi)) | ||
given Foo = new Foo | ||
val i1: Int = Seq(0) match { | ||
case Bar(i, _) => i | ||
case _ => 0 | ||
} | ||
} |
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,14 @@ | ||
object Bar { | ||
class Foo { | ||
def m1(i: Int) = i + i1 | ||
def m2(i: Int) = i + 2 | ||
} | ||
def unapply(using f1: Foo)(using f2: Foo)(i: Int)(using f3: Foo): Option[Int] = | ||
if i == 0 then Some(f1.m1(i1) + f3.m1(i1)) else Some(f2.m2(i) + f3.m2(i)) | ||
|
||
given Foo = new Foo | ||
val i1: Int = 0 | ||
val i2: Int = i1 match | ||
case Bar(i) => i | ||
case _ => 0 | ||
} |
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,14 @@ | ||
object Bar { | ||
class Foo { | ||
def m1(seq: Seq[Int]) = 0 +: seq | ||
def m2(seq: Seq[Int]) = i1 +: seq | ||
} | ||
def unapplySeq(using f1: Foo)(using f2: Foo)(seqi: Seq[Int])(using f3: Foo): Option[Seq[Int]] = | ||
if seqi(0) == 0 then Some(f1.m1(seqi)) else Some(f2.m2(seqi)) | ||
|
||
given Foo = new Foo | ||
val i1: Int = 0 | ||
val i2: Int = Seq(i1) match | ||
case Bar(i) => i | ||
case _ => 0 | ||
} |