Skip to content

Commit 4b00c5c

Browse files
committed
Update tests
1 parent adc549b commit 4b00c5c

File tree

7 files changed

+98
-6
lines changed

7 files changed

+98
-6
lines changed

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,19 @@ class CompilationTests {
212212
compileFilesInDir("tests/explicit-nulls/neg", explicitNullsOptions, FileFilter.exclude(TestSources.negExplicitNullsScala2LibraryTastyExcludelisted)),
213213
compileFilesInDir("tests/explicit-nulls/flexible-types-common", explicitNullsOptions and "-Yno-flexible-types"),
214214
compileFilesInDir("tests/explicit-nulls/unsafe-common", explicitNullsOptions and "-Yno-flexible-types", FileFilter.exclude(TestSources.negExplicitNullsScala2LibraryTastyExcludelisted)),
215-
)
216-
}.checkExpectedErrors()
215+
).checkExpectedErrors()
216+
217+
locally {
218+
val unsafeFile = compileFile("tests/explicit-nulls/flexible-unpickle/neg/Unsafe_1.scala", explicitNullsOptions without "-Yexplicit-nulls")
219+
val flexibleFile = compileFile("tests/explicit-nulls/flexible-unpickle/neg/Flexible_2.scala",
220+
explicitNullsOptions.withClasspath(defaultOutputDir + testGroup + "/Unsafe_1/neg/Unsafe_1"))
221+
222+
flexibleFile.keepOutput.checkExpectedErrors()
223+
224+
List(unsafeFile, flexibleFile).foreach(_.delete())
225+
}
226+
}
217227

218-
@Ignore
219228
@Test def explicitNullsPos: Unit = {
220229
implicit val testGroup: TestGroup = TestGroup("explicitNullsPos")
221230
aggregateTests(
@@ -226,9 +235,9 @@ class CompilationTests {
226235

227236
locally {
228237
val tests = List(
229-
compileFile("tests/explicit-nulls/flexible-unpickle/Unsafe_1.scala", explicitNullsOptions without "-Yexplicit-nulls"),
230-
compileFile("tests/explicit-nulls/flexible-unpickle/Flexible_2.scala", explicitNullsOptions.withClasspath(
231-
defaultOutputDir + testGroup + "/Unsafe_1/flexible-unpickle/Unsafe_1")),
238+
compileFile("tests/explicit-nulls/flexible-unpickle/pos/Unsafe_1.scala", explicitNullsOptions without "-Yexplicit-nulls"),
239+
compileFile("tests/explicit-nulls/flexible-unpickle/pos/Flexible_2.scala", explicitNullsOptions.withClasspath(
240+
defaultOutputDir + testGroup + "/Unsafe_1/pos/Unsafe_1")),
232241
).map(_.keepOutput.checkCompile())
233242

234243
tests.foreach(_.delete())
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import unsafe.*
2+
3+
@A[String] class C
4+
5+
def test =
6+
7+
val ii = Bar.f[Int](null) // error
8+
val jj = Bar.g[String](null) // error
9+
val jj2 = Bar.g[String | Null](null) // ok
10+
val kk = Bar.g2[String](null) // error
11+
val kk2 = Bar.g2[String | Null](null) // ok
12+
13+
val bar_x: Int = Bar.x
14+
val bar_y: String | Null = Bar.y.replaceAll(" ","")
15+
16+
def testUsingFoo(using Foo[Option]) = Bar.h(null)
17+
18+
val ii2 = Bar2[String]().f(null) // error
19+
val ii3 = Bar2[String | Null]().f(null) // ok
20+
21+
val a = Bar.ff(
22+
(x: AnyRef) => x.toString,
23+
42
24+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package unsafe
2+
3+
import scala.annotation.*
4+
5+
type XtoY = [X] =>> [Y] =>> X => Y
6+
7+
class Foo[T[_]]
8+
9+
class A[T] extends Annotation
10+
11+
object Bar:
12+
def ff(f: AnyRef => String, g: AnyRef ?=> Int): (AnyRef => String) = ???
13+
var x: Int = 0
14+
var y: String = ""
15+
def f[T <: Int](x: T): T = x
16+
def g[T <: AnyRef](x: T): T = x
17+
def g2[T >: Null <: AnyRef](x: T): T = x
18+
def h(x: String)(using Foo[Option]): String = x
19+
def h2(a: Foo[XtoY[String]]) = ???
20+
21+
class Bar2[T]:
22+
def f(x: T): T = x

tests/explicit-nulls/flexible-unpickle/Flexible_2.scala renamed to tests/explicit-nulls/flexible-unpickle/pos/Flexible_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,8 @@ def Flexible_2() =
115115
expects(alphaTypeNameMacro[A])
116116
}
117117

118+
// i23935
119+
opaque type ZArrow[-I, -R, +E, +O] = I => ZIO[R, E, O]
120+
object ZArrow:
121+
def fromZIOAttempt[I, R, E, O](f: I => ZIO[R, E, O]): ZArrow[I, R, Throwable | E, O] =
122+
(in: I) => ZIO.attempt(f(in)).flatten

tests/explicit-nulls/flexible-unpickle/Unsafe_1.scala renamed to tests/explicit-nulls/flexible-unpickle/pos/Unsafe_1.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,13 @@ class T
8484
class U[Y](a: Y)
8585
def expects(take: (T) ?=> U[String]) = ???
8686

87+
// i23935
88+
object ZIO:
89+
def attempt[A](code: => A): ZIO[Any, Throwable, A] = ???
90+
91+
trait ZIO[-R, +E, +A]:
92+
final def flatten[R1 <: R, E1 >: E, B](using A IsSubtypeOfOutput ZIO[R1, E1, B]): ZIO[R1, E1, B] = ???
93+
94+
infix sealed abstract class IsSubtypeOfOutput[-A, +B]
95+
object IsSubtypeOfOutput:
96+
given [A, B](using A <:< B): IsSubtypeOfOutput[A, B] = ???
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
enum FormatPattern:
2+
case AsInt
3+
case AsLong
4+
5+
// some basic operations with enum:
6+
def test =
7+
val p1 = FormatPattern.AsInt
8+
val p2 = FormatPattern.AsLong
9+
val p3 = FormatPattern.valueOf("AsInt")
10+
val p4 = FormatPattern.values(0)
11+
val ord1 = p1.ordinal
12+
val ord2 = p2.ordinal
13+
val str1 = p1.toString()
14+
val str2 = p2.toString()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//> using options -Yexplicit-nulls
2+
3+
sealed abstract class IsSubtypeOfOutput[-A, +B] extends (A => B)
4+
object IsSubtypeOfOutput:
5+
private val instance: IsSubtypeOfOutput[Any, Any] = new IsSubtypeOfOutput[Any, Any] { def apply(a: Any): Any = a }
6+
7+
sealed trait DerivationAnnotation
8+
class Rename(name: String) extends DerivationAnnotation

0 commit comments

Comments
 (0)