-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support implicit arguments before extractor method #18671
Merged
olhotak
merged 5 commits into
scala:main
from
dotty-staging:object-initialization-implicit-unapply
Oct 16, 2023
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6574b32
Support implicit arguments before extractor method
e99c982
Correct argument order in evalPattern and add test
508c2d2
Address comments
231a4a7
Update compiler/src/dotty/tools/dotc/transform/init/Objects.scala
olhotak 6c34ce4
Update compiler/src/dotty/tools/dotc/transform/init/Objects.scala
olhotak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: This line is a little long , maybe extract
implicitValuesBeforeScrutinee(fun) ++ (TraceValue(scrutinee, summon[Trace]) :: implicitValuesAfterScrtinee)
to a local definition.