Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
require @unchecked for effect casts, support effect ascriptions.
fixes #5
- Loading branch information
Showing
14 changed files
with
215 additions
and
44 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
94 changes: 94 additions & 0 deletions
94
...t/resources/scala/tools/nsc/effects/io/AscriptionsCastsSuite-files/ascriptionsCasts.scala
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,94 @@ | ||
import annotation.effects._ | ||
|
||
class C { | ||
def no: Unit @noIo = () | ||
def yo: Unit @io = () | ||
|
||
|
||
// pos ascription | ||
def f1 = { | ||
if (true) (no: @noIo) else (yo: @io) | ||
(no: @io) | ||
} | ||
|
||
// pos cast | ||
def f4: Unit @noIo = { | ||
(yo: @noIo @unchecked) | ||
} | ||
|
||
// pos cast | ||
def f5: Unit @noIo = { | ||
(yo: @unchecked @noIo) | ||
} | ||
|
||
// pos cast | ||
def f6: Unit @unchecked @noIo = { | ||
yo | ||
} | ||
|
||
// pos cast | ||
@unchecked @pure | ||
class C1 { | ||
println() | ||
} | ||
def t1: C1 @pure = new C1 | ||
|
||
// pos cast | ||
class C2 { | ||
@unchecked @pure type constructorEffect | ||
println() | ||
} | ||
def t2: C2 @pure = new C2 | ||
|
||
// pos cast | ||
class C3 { | ||
@unchecked @pure def this(x: Int) = { | ||
this() | ||
println() | ||
} | ||
} | ||
def t3: C3 @pure = new C3(2) | ||
|
||
// pos cast | ||
class C4 { | ||
def this(x: Int) = { | ||
this() | ||
@unchecked @pure type constructorEffect = Nothing | ||
println() | ||
} | ||
} | ||
def t4: C4 @pure = new C4(2) | ||
} | ||
|
||
class C1 { | ||
import scala.{unchecked => un} | ||
|
||
def no: Unit @noIo = () | ||
def yo: Unit @io = () | ||
|
||
def f4: Unit @noIo = { | ||
(yo: @un @noIo) | ||
} | ||
} | ||
|
||
class C2 { | ||
import scala.{unchecked => !} | ||
|
||
def no: Unit @noIo = () | ||
def yo: Unit @io = () | ||
|
||
def f4: Unit @noIo = { | ||
(yo: @`!` @noIo) | ||
} | ||
} | ||
|
||
class C3 { | ||
type un = scala.unchecked | ||
|
||
def no: Unit @noIo = () | ||
def yo: Unit @io = () | ||
|
||
def f4: Unit @noIo = { | ||
(yo: @un @noIo) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...esources/scala/tools/nsc/effects/io/AscriptionsCastsSuite-files/ascriptionsCastsNeg.check
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 @@ | ||
newSource:9: error: effect type mismatch; | ||
found : @io | ||
required: @noIo | ||
(no: @io) | ||
^ | ||
newSource:14: error: effect type mismatch; | ||
found : @io | ||
required: @noIo | ||
(yo: @noIo) | ||
^ |
16 changes: 16 additions & 0 deletions
16
...esources/scala/tools/nsc/effects/io/AscriptionsCastsSuite-files/ascriptionsCastsNeg.scala
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,16 @@ | ||
import annotation.effects._ | ||
|
||
class C { | ||
def no: Unit @noIo = () | ||
def yo: Unit @io = () | ||
|
||
// neg ascription | ||
def f2: Unit @noIo = { | ||
(no: @io) | ||
} | ||
|
||
// neg ascription | ||
def f3: Unit @noIo = { | ||
(yo: @noIo) | ||
} | ||
} |
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
8 changes: 6 additions & 2 deletions
8
tests/src/test/resources/scala/tools/nsc/effects/multi/ExceptionsIoPurity-files/casts.scala
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import annotation.effects.{io, pure} | ||
|
||
class C { | ||
def show(a: Any): Unit @pure @io = { | ||
class A { | ||
def s: String = "" | ||
} | ||
|
||
def show(a: A): Unit @pure @io = { | ||
// need an additional cast because the argument is ANF-lifted to a local variable, | ||
// and it ends up outside the other ascription. | ||
println(a.toString: @pure): @pure @io | ||
println(a.s: @unchecked @pure): @unchecked @pure @io | ||
} | ||
} |
Oops, something went wrong.