-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not compute protoFormal
if param.tpt
is empty
#18288
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1606,32 +1606,31 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer | |
if desugared.isEmpty then | ||
val inferredParams: List[untpd.ValDef] = | ||
for ((param, i) <- params.zipWithIndex) yield | ||
val (formalBounds, isErased) = protoFormal(i) | ||
val param0 = | ||
if (!param.tpt.isEmpty) param | ||
else | ||
val formal = formalBounds.loBound | ||
val isBottomFromWildcard = (formalBounds ne formal) && formal.isExactlyNothing | ||
val knownFormal = isFullyDefined(formal, ForceDegree.failBottom) | ||
// If the expected formal is a TypeBounds wildcard argument with Nothing as lower bound, | ||
// try to prioritize inferring from target. See issue 16405 (tests/run/16405.scala) | ||
val paramType = | ||
// Strip inferred erased annotation, to avoid accidentally inferring erasedness | ||
val formal0 = if !isErased then formal.stripAnnots(_.symbol != defn.ErasedParamAnnot) else formal | ||
if knownFormal && !isBottomFromWildcard then | ||
formal0 | ||
else | ||
inferredFromTarget(param, formal, calleeType, isErased, paramIndex).orElse( | ||
if knownFormal then formal0 | ||
else errorType(AnonymousFunctionMissingParamType(param, tree, inferredType = formal, expectedType = pt), param.srcPos) | ||
) | ||
val paramTpt = untpd.TypedSplice( | ||
(if knownFormal then InferredTypeTree() else untpd.TypeTree()) | ||
.withType(paramType.translateFromRepeated(toArray = false)) | ||
.withSpan(param.span.endPos) | ||
if (!param.tpt.isEmpty) param | ||
else | ||
val (formalBounds, isErased) = protoFormal(i) | ||
val formal = formalBounds.loBound | ||
val isBottomFromWildcard = (formalBounds ne formal) && formal.isExactlyNothing | ||
val knownFormal = isFullyDefined(formal, ForceDegree.failBottom) | ||
// If the expected formal is a TypeBounds wildcard argument with Nothing as lower bound, | ||
// try to prioritize inferring from target. See issue 16405 (tests/run/16405.scala) | ||
val paramType = | ||
// Strip inferred erased annotation, to avoid accidentally inferring erasedness | ||
val formal0 = if !isErased then formal.stripAnnots(_.symbol != defn.ErasedParamAnnot) else formal | ||
if knownFormal && !isBottomFromWildcard then | ||
formal0 | ||
else | ||
inferredFromTarget(param, formal, calleeType, isErased, paramIndex).orElse( | ||
if knownFormal then formal0 | ||
else errorType(AnonymousFunctionMissingParamType(param, tree, inferredType = formal, expectedType = pt), param.srcPos) | ||
) | ||
cpy.ValDef(param)(tpt = paramTpt) | ||
if isErased then param0.withAddedFlags(Flags.Erased) else param0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this was moved into the |
||
val paramTpt = untpd.TypedSplice( | ||
(if knownFormal then InferredTypeTree() else untpd.TypeTree()) | ||
.withType(paramType.translateFromRepeated(toArray = false)) | ||
.withSpan(param.span.endPos) | ||
) | ||
val param0 = cpy.ValDef(param)(tpt = paramTpt) | ||
if isErased then param0.withAddedFlags(Flags.Erased) else param0 | ||
desugared = desugar.makeClosure(Nil, inferredParams, fnBody, resultTpt, tree.span) | ||
|
||
typed(desugared, pt) | ||
|
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,15 @@ | ||
import scala.language.implicitConversions | ||
|
||
case class Assign(left: String, right: String) | ||
class SyntaxAnalyser extends ParsersBase { | ||
val x: Parser[String ~ String] = ??? | ||
val y: Parser[Assign] = x.map(Assign.apply) | ||
} | ||
|
||
class ParsersBase { | ||
trait ~[+T, +U] | ||
abstract class Parser[+T]: | ||
def map[U](f: T => U): Parser[U] = ??? | ||
|
||
given [A, B, X]: Conversion[(A, B) => X, (A ~ B) => X] = ??? | ||
} |
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,9 @@ | ||
import scala.language.implicitConversions | ||
|
||
def foo(a: Int): Int = ??? | ||
def bar(f: () => Int): Int = ??? | ||
|
||
given f: Conversion[Int => Int, () => Int] = ??? | ||
|
||
def test1: Int = bar(foo) // implicit conversion applied to foo | ||
def test2: Int = bar(f(foo)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line moved into the else branch. The rest should not have changed.