Skip to content

Commit 2415280

Browse files
committed
Disallow maybes with wildcard arguments
1 parent 77cd4c5 commit 2415280

6 files changed

Lines changed: 17 additions & 35 deletions

File tree

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,13 @@ object Checking {
129129
checkBounds(args, bounds, instantiate, tree.tpe, tpt)
130130

131131
def checkWildcardApply(tp: Type): Unit = tp match {
132-
case tp @ AppliedType(tycon, _) =>
132+
case tp @ AppliedType(tycon, _) if tp.hasWildcardArg =>
133133
if tp.isUnreducibleWild then
134134
report.errorOrMigrationWarning(
135135
showInferred(UnreducibleApplication(tycon), tp, tpt),
136136
tree.srcPos, MigrationVersion.Scala2to3)
137+
else if tp.typeSymbol == defn.MagicMaybeClass then
138+
report.error(em"Maybe type may not contain wildcard arguments", tree.srcPos)
137139
case _ =>
138140
}
139141
def checkValidIfApply(using Context): Unit =
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
//> using options -Yexplicit-nulls
22
import language.experimental.magic
3-
object Ex { def unapply(p: Any): (? <: Int)? = null }
3+
object Ex { def unapply(p: Any): (? <: Int)? = null } // error
44
object Foo { val Ex(_) = null: @unchecked }

tests/neg/t8128-maybe.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg/t8128-maybe.scala:6:23 -----------------------------------------------------------------------------
2+
6 | def unapply(m: Any): Maybe[?, Unit] = Ok("") // error
3+
| ^^^^^^^^^^^^^^
4+
| Maybe type may not contain wildcard arguments

tests/neg/t8128-maybe.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//> using options -Yexplicit-nulls
2+
import language.experimental.magic
3+
import scala.magic.*
4+
import compiletime.Maybe
5+
object G {
6+
def unapply(m: Any): Maybe[?, Unit] = Ok("") // error
7+
}
8+

tests/pos/extractor-types-maybe.scala

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/pos/t8128-maybe.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import language.experimental.magic
33
import scala.magic.*
44
import compiletime.Maybe
55
object G {
6-
def unapply(m: Any): Maybe[?, Unit] = Ok("")
6+
def unapply(m: Any): Maybe[Any, Unit] = Ok("")
77
}
88

99
object H {

0 commit comments

Comments
 (0)