-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #11178: remove unsound tweak for F-bounds in isInstanceOf check #11768
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
6 commits
Select commit
Hold shift + click to select a range
f5d582e
Fix #11178: remove unsound tweak for F-bounds
liufengyun 58f0f29
Fix unchecked warning in scaladoc
liufengyun 7f64866
Add test
liufengyun b5df339
Fix unchecked warnings in test
liufengyun 9b8b812
Simplify algorithm
liufengyun aa296ba
Add comment for code
liufengyun 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
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,18 @@ | ||
object HTML: | ||
type AttrArg = AppliedAttr | Seq[AppliedAttr] | ||
opaque type AppliedAttr = String | ||
opaque type AppliedTag = StringBuilder | ||
|
||
case class Tag(name: String): | ||
def apply(attrs: AttrArg*): AppliedTag = { | ||
val sb = StringBuilder() | ||
sb.append(s"<$name") | ||
attrs.filter(_ != Nil).foreach{ | ||
case s: Seq[AppliedAttr] => | ||
s.foreach(sb.append(" ").append) | ||
case s: Seq[Int] => // error | ||
case e: AppliedAttr => | ||
sb.append(" ").append(e) | ||
} | ||
sb | ||
} |
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,39 @@ | ||
trait Box[+T] | ||
case class Foo[+S](s: S) extends Box[S] | ||
|
||
def unwrap2[A](b: Box[A]): A = | ||
b match | ||
case _: Foo[Int] => 0 // error | ||
|
||
object Test1 { | ||
// Invariant case, OK | ||
sealed trait Bar[A] | ||
|
||
def test[A](bar: Bar[A]) = | ||
bar match { | ||
case _: Bar[Boolean] => ??? // error | ||
case _ => ??? | ||
} | ||
} | ||
|
||
object Test2 { | ||
// Covariant case | ||
sealed trait Bar[+A] | ||
|
||
def test[A](bar: Bar[A]) = | ||
bar match { | ||
case _: Bar[Boolean] => ??? // error | ||
case _ => ??? | ||
} | ||
} | ||
|
||
object Test3 { | ||
// Contravariant case | ||
sealed trait Bar[-A] | ||
|
||
def test[A](bar: Bar[A]) = | ||
bar match { | ||
case _: Bar[Boolean] => ??? // error | ||
case _ => ??? | ||
} | ||
} |
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.
I think I understand the intent here, but it's a bit surprising that we don't widen the params, given that doing so is necessary for soundness. What would be a motivating example for not widening them here?
Uh oh!
There was an error while loading. Please reload this page.
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.
The motivation for not widening is something specific to the algorithm: here for
P1 = pre.F[Xs]
, allXs
are type variables. We want theXs
to be constrained.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.
I feel very happy the work on the GADT makes the checking so elegant that we remove a lot of ad-hoc tweaks. The fact that the algorithm is simpler and it found more bugs in the compiler gives more confidence.
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.
One example is the following:
In checking whether the test
tree.isInstanceOf[JavaSeqLiteral[Type]]
is realizable, we want to constrainJavaSeqLiteral[X] <: Tree[Type]
, such that we can inferX = Type
andJavaSeqLiteral[X] <:< JavaSeqLiteral[Type]
.If we perform widening, we will get
X = Nothing
, and we don't haveJavaSeqLiteral[X] <:< JavaSeqLiteral[Type]
any more.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.
Ok, I think what we're doing here is sound, but with small changes we could easily make it unsound. I'll need to add a comment explaining what's going on, and then we can merge the PR.
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.
Yes, I'll add a comment explaining the code.
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.
Comment added in aa296ba