Skip to content

Commit 29dc069

Browse files
committed
Redefine hasCaptureConversionArg
1 parent 0893dc3 commit 29dc069

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4470,8 +4470,6 @@ object Types {
44704470

44714471
def hasWildcardArg(using Context): Boolean = args.exists(isBounds)
44724472

4473-
def hasCaptureConversionArg(using Context): Boolean = args.exists(_.typeSymbol == defn.TypeBox_CAP)
4474-
44754473
def derivedAppliedType(tycon: Type, args: List[Type])(using Context): Type =
44764474
if ((tycon eq this.tycon) && (args eq this.args)) this
44774475
else tycon.appliedTo(args)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ object Inferencing {
546546
case tp: AnnotatedType => tp.derivedAnnotatedType(captureWildcards(tp.parent), tp.annot)
547547
case _ => tp
548548
}
549+
550+
def hasCaptureConversionArg(tp: Type)(using Context): Boolean = tp match
551+
case tp: AppliedType => tp.args.exists(_.typeSymbol == defn.TypeBox_CAP)
552+
case _ => false
549553
}
550554

551555
trait Inferencing { this: Typer =>

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Decorators._
1313
import Uniques._
1414
import inlines.Inlines
1515
import config.Printers.typr
16+
import Inferencing.*
1617
import ErrorReporting.*
1718
import util.SourceFile
1819
import TypeComparer.necessarySubType
@@ -495,18 +496,21 @@ object ProtoTypes {
495496
force = true)
496497
val targ1 = typer.adapt(targ, wideFormal, locked)
497498
if wideFormal eq formal then targ1
498-
else targ1.tpe match
499-
case tp: AppliedType if tp.hasCaptureConversionArg =>
500-
stripCast(targ1).tpe match
501-
case tp: AppliedType if tp.hasWildcardArg =>
502-
errorTree(targ1,
503-
em"""argument for by-name parameter is not a value
504-
|and contains wildcard arguments: $tp
505-
|
506-
|Assign it to a val and pass that instead.
507-
|""")
508-
case _ => targ1
509-
case _ => targ1
499+
else checkNoWildcardCaptureForCBN(targ1)
500+
}
501+
502+
def checkNoWildcardCaptureForCBN(targ1: Tree)(using Context): Tree = {
503+
if hasCaptureConversionArg(targ1.tpe) then
504+
stripCast(targ1).tpe match
505+
case tp: AppliedType if tp.hasWildcardArg =>
506+
errorTree(targ1,
507+
em"""argument for by-name parameter is not a value
508+
|and contains wildcard arguments: $tp
509+
|
510+
|Assign it to a val and pass that instead.
511+
|""")
512+
case _ => targ1
513+
else targ1
510514
}
511515

512516
/** The type of the argument `arg`, or `NoType` if `arg` has not been typed before

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
15681568
else if ((tree.tpt `eq` untpd.ContextualEmptyTree) && mt.paramNames.isEmpty)
15691569
// Note implicitness of function in target type since there are no method parameters that indicate it.
15701570
TypeTree(defn.FunctionOf(Nil, mt.resType, isContextual = true, isErased = false))
1571-
else if mt.resType.match { case tp: AppliedType => tp.hasCaptureConversionArg case _ => false } then
1571+
else if hasCaptureConversionArg(mt.resType) then
15721572
errorTree(tree,
15731573
em"""cannot turn method type $mt into closure
15741574
|because it has capture conversion skolem types""")

0 commit comments

Comments
 (0)