Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SI-6331 Avoid typing an If tree with a constant type.
The fast path in typedIf added in 8552740 avoided lubbing the if/else branch types if they are identical, but this fails to deconst the type. This could lead to the entire if expression being replaced by a constant. Also introduces a new tool in partest for nicer checkfiles. // in Test.scala trace(if (t) -0d else 0d) // in Test.check trace> if (Test.this.t) -0.0 else 0.0 res: Double = -0.0
- Loading branch information
Showing
4 changed files
with
78 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
trace> if (Test.this.t) | ||
-0.0 | ||
else | ||
0.0 | ||
res: Double = -0.0 | ||
|
||
trace> if (Test.this.t) | ||
0.0 | ||
else | ||
-0.0 | ||
res: Double = 0.0 | ||
|
||
trace> Test.this.intercept.apply[Any](if (scala.this.Predef.???) | ||
-0.0 | ||
else | ||
0.0) | ||
res: Any = class scala.NotImplementedError | ||
|
||
trace> Test.this.intercept.apply[Any](if (scala.this.Predef.???) | ||
0.0 | ||
else | ||
0.0) | ||
res: Any = class scala.NotImplementedError | ||
|
||
trace> Test.this.intercept.apply[Any](if (scala.this.Predef.???) | ||
() | ||
else | ||
()) | ||
res: Any = class scala.NotImplementedError | ||
|
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,20 @@ | ||
import scala.tools.partest._ | ||
import java.io._ | ||
import scala.tools.nsc._ | ||
import scala.tools.nsc.util.CommandLineParser | ||
import scala.tools.nsc.{Global, Settings, CompilerCommand} | ||
import scala.tools.nsc.reporters.ConsoleReporter | ||
|
||
import scala.tools.partest.trace | ||
import scala.util.control.Exception._ | ||
|
||
|
||
object Test extends App { | ||
def intercept = allCatch.withApply(_.getClass) | ||
val t: Boolean = true | ||
trace(if (t) -0d else 0d) | ||
trace(if (t) 0d else -0d) | ||
trace(intercept(if (???) -0d else 0d)) | ||
trace(intercept(if (???) 0d else 0d)) | ||
trace(intercept(if (???) () else ())) | ||
} |