-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4564: Invalidate clashing case class methods #4813
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,46 @@ | ||
object ClashOverloadNoSig { | ||
|
||
private def apply(x: Int) = if (x > 0) new ClashOverloadNoSig(x) else apply("") // error: overloaded method apply needs result type | ||
|
||
def apply(x: String): ClashOverloadNoSig = ??? | ||
} | ||
|
||
case class ClashOverloadNoSig private(x: Int) | ||
|
||
object ClashRecNoSig { | ||
private def apply(x: Int) = if (x > 0) ClashRecNoSig(1) else ??? // error: recursive method apply needs result type | ||
} | ||
|
||
case class ClashRecNoSig private(x: Int) | ||
|
||
object NoClashNoSig { | ||
private def apply(x: Boolean) = if (x) NoClashNoSig(1) else ??? // error: overloaded method apply needs result type | ||
} | ||
|
||
case class NoClashNoSig private(x: Int) | ||
|
||
object NoClashOverload { | ||
private def apply(x: Boolean) = if (x) NoClashOverload(1) else apply("") // error // error: overloaded method apply needs result type (twice) | ||
|
||
def apply(x: String): NoClashOverload = ??? | ||
} | ||
|
||
case class NoClashOverload private(x: Int) | ||
|
||
|
||
class BaseNCNSP[T] { | ||
def apply(x: T) = if (???) NoClashNoSigPoly(1) else ??? // error: overloaded method apply needs result type | ||
} | ||
|
||
object NoClashNoSigPoly extends BaseNCNSP[Boolean] | ||
case class NoClashNoSigPoly private(x: Int) // ok, since `apply` is in base class | ||
|
||
|
||
|
||
class BaseCNSP[T] { | ||
def apply(x: T) = if (???) ClashNoSigPoly(1) else ??? // error: recursive method apply needs result type | ||
} | ||
|
||
object ClashNoSigPoly extends BaseCNSP[Int] | ||
// TODO: improve error message | ||
case class ClashNoSigPoly private(x: Int) // error: found: ClashNoSigPoly required: Nothing |
This file contains hidden or 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,62 @@ | ||
case class A(x: Int) { | ||
def copy(x: Int = x) = A(x) | ||
} | ||
|
||
// NOTE: the companion inherits a public apply method from Function1! | ||
case class NeedsCompanion private (x: Int) | ||
|
||
object ClashNoSig { // ok | ||
private def apply(x: Int) = if (x > 0) new ClashNoSig(x) else ??? | ||
def unapply(x: ClashNoSig) = x | ||
|
||
ClashNoSig(2) match { | ||
case c @ ClashNoSig(y) => c.copy(y + c._1) | ||
} | ||
} | ||
case class ClashNoSig private (x: Int) { | ||
def copy(y: Int) = ClashNoSig(y) | ||
} | ||
|
||
object Clash { | ||
private def apply(x: Int) = if (x > 0) new Clash(x) else ??? | ||
} | ||
case class Clash private (x: Int) | ||
|
||
object ClashSig { | ||
private def apply(x: Int): ClashSig = if (x > 0) new ClashSig(x) else ??? | ||
} | ||
case class ClashSig private (x: Int) | ||
|
||
object ClashOverload { | ||
private def apply(x: Int): ClashOverload = if (x > 0) new ClashOverload(x) else apply("") | ||
def apply(x: String): ClashOverload = ??? | ||
} | ||
case class ClashOverload private (x: Int) | ||
|
||
object NoClashSig { | ||
private def apply(x: Boolean): NoClashSig = if (x) NoClashSig(1) else ??? | ||
} | ||
case class NoClashSig private (x: Int) | ||
|
||
object NoClashOverload { | ||
// needs full sig | ||
private def apply(x: Boolean): NoClashOverload = if (x) NoClashOverload(1) else apply("") | ||
def apply(x: String): NoClashOverload = ??? | ||
} | ||
case class NoClashOverload private (x: Int) | ||
|
||
class BaseNCP[T] { | ||
// error: overloaded method apply needs result type | ||
def apply(x: T): NoClashPoly = if (???) NoClashPoly(1) else ??? | ||
} | ||
|
||
object NoClashPoly extends BaseNCP[Boolean] | ||
case class NoClashPoly private(x: Int) | ||
|
||
|
||
class BaseCP[T] { | ||
// error: overloaded method apply needs result type | ||
def apply(x: T): ClashPoly = if (???) ClashPoly(1) else ??? | ||
} | ||
object ClashPoly extends BaseCP[Int] | ||
case class ClashPoly private(x: Int) |
This file contains hidden or 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,13 @@ | ||
object Foo { | ||
// spurious error if: | ||
// - this definition precedes that of apply (which is overloaded with the synthetic one derived from the case class) | ||
// - AND `Foo.apply` is explicitly applied to `[A]` (no error if `[A]` is inferred) | ||
// | ||
def referToPolyOverloadedApply[A]: Foo[A] = Foo.apply[A]("bla") | ||
// ^ | ||
// found : String("bla") | ||
// required: Int | ||
|
||
def apply[A](x: Int): Foo[A] = ??? | ||
} | ||
case class Foo[A](x: String) |
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.
There's also a negative version -- would be good to include.