Skip to content

Commit

Permalink
Redefine hasCaptureConversionArg
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jan 23, 2023
1 parent 0893dc3 commit 29dc069
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4470,8 +4470,6 @@ object Types {

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

def hasCaptureConversionArg(using Context): Boolean = args.exists(_.typeSymbol == defn.TypeBox_CAP)

def derivedAppliedType(tycon: Type, args: List[Type])(using Context): Type =
if ((tycon eq this.tycon) && (args eq this.args)) this
else tycon.appliedTo(args)
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,10 @@ object Inferencing {
case tp: AnnotatedType => tp.derivedAnnotatedType(captureWildcards(tp.parent), tp.annot)
case _ => tp
}

def hasCaptureConversionArg(tp: Type)(using Context): Boolean = tp match
case tp: AppliedType => tp.args.exists(_.typeSymbol == defn.TypeBox_CAP)
case _ => false
}

trait Inferencing { this: Typer =>
Expand Down
28 changes: 16 additions & 12 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Decorators._
import Uniques._
import inlines.Inlines
import config.Printers.typr
import Inferencing.*
import ErrorReporting.*
import util.SourceFile
import TypeComparer.necessarySubType
Expand Down Expand Up @@ -495,18 +496,21 @@ object ProtoTypes {
force = true)
val targ1 = typer.adapt(targ, wideFormal, locked)
if wideFormal eq formal then targ1
else targ1.tpe match
case tp: AppliedType if tp.hasCaptureConversionArg =>
stripCast(targ1).tpe match
case tp: AppliedType if tp.hasWildcardArg =>
errorTree(targ1,
em"""argument for by-name parameter is not a value
|and contains wildcard arguments: $tp
|
|Assign it to a val and pass that instead.
|""")
case _ => targ1
case _ => targ1
else checkNoWildcardCaptureForCBN(targ1)
}

def checkNoWildcardCaptureForCBN(targ1: Tree)(using Context): Tree = {
if hasCaptureConversionArg(targ1.tpe) then
stripCast(targ1).tpe match
case tp: AppliedType if tp.hasWildcardArg =>
errorTree(targ1,
em"""argument for by-name parameter is not a value
|and contains wildcard arguments: $tp
|
|Assign it to a val and pass that instead.
|""")
case _ => targ1
else targ1
}

/** The type of the argument `arg`, or `NoType` if `arg` has not been typed before
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
else if ((tree.tpt `eq` untpd.ContextualEmptyTree) && mt.paramNames.isEmpty)
// Note implicitness of function in target type since there are no method parameters that indicate it.
TypeTree(defn.FunctionOf(Nil, mt.resType, isContextual = true, isErased = false))
else if mt.resType.match { case tp: AppliedType => tp.hasCaptureConversionArg case _ => false } then
else if hasCaptureConversionArg(mt.resType) then
errorTree(tree,
em"""cannot turn method type $mt into closure
|because it has capture conversion skolem types""")
Expand Down

0 comments on commit 29dc069

Please sign in to comment.