-
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 #14715 from dotty-staging/fix-14705-v2
Don't optimize explicitly written isInstanceOf tests away.
- Loading branch information
Showing
8 changed files
with
68 additions
and
25 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
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
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,3 @@ | ||
val n = Nil | ||
val b = n.head.isInstanceOf[String] // error | ||
|
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,17 @@ | ||
class Tree | ||
case class Inlined(call: Tree, bindings: List[String], expr: Tree) extends Tree | ||
case object EmptyTree extends Tree | ||
class Context | ||
|
||
class Transform: | ||
def transform(tree: Tree)(using Context): Tree = tree | ||
|
||
class Inliner: | ||
var enclosingInlineds: List[String] = Nil | ||
private def expandMacro(using Context) = | ||
val inlinedNormalizer = new Transform: | ||
override def transform(tree: Tree)(using Context) = tree match | ||
case Inlined(EmptyTree, Nil, expr) if enclosingInlineds.isEmpty => transform(expr) | ||
case _ => super.transform(tree) | ||
|
||
object Inliner |
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,19 @@ | ||
trait Fruit | ||
case class Apple() extends Fruit | ||
case class Orange() extends Fruit | ||
|
||
case class Box[C](fruit: C) extends Fruit | ||
|
||
val apple = Box(fruit = Apple()) | ||
val orange = Box(fruit = Orange()) | ||
|
||
|
||
val result = List(apple, orange).map { | ||
case appleBox: Box[Apple] @unchecked if appleBox.fruit.isInstanceOf[Apple] => //contains apple | ||
"apple" | ||
case _ => | ||
"orange" | ||
} | ||
|
||
@main def Test = | ||
assert(result == List("apple", "orange")) |