Skip to content

Commit 2b29ffb

Browse files
som-snyttWojciechMazur
authored andcommitted
Vertical alignment in adaptOverloaded
[Cherry-picked da1e073]
1 parent c8869a9 commit 2b29ffb

File tree

1 file changed

+41
-48
lines changed

1 file changed

+41
-48
lines changed

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

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4306,54 +4306,47 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43064306
val alts = altDenots.map(altRef)
43074307

43084308
resolveOverloaded(alts, pt) match
4309-
case alt :: Nil =>
4310-
readaptSimplified(tree.withType(alt))
4311-
case Nil =>
4312-
// If no alternative matches, there are still two ways to recover:
4313-
// 1. If context is an application, try to insert an apply or implicit
4314-
// 2. If context is not an application, pick a alternative that does
4315-
// not take parameters.
4316-
4317-
def errorNoMatch = errorTree(tree, NoMatchingOverload(altDenots, pt))
4318-
4319-
pt match
4320-
case pt: FunOrPolyProto if pt.applyKind != ApplyKind.Using =>
4321-
// insert apply or convert qualifier, but only for a regular application
4322-
tryInsertApplyOrImplicit(tree, pt, locked)(errorNoMatch)
4323-
case _ =>
4324-
tryParameterless(alts)(errorNoMatch)
4325-
4326-
case ambiAlts =>
4327-
// If there are ambiguous alternatives, and:
4328-
// 1. the types aren't erroneous
4329-
// 2. the expected type is not a function type
4330-
// 3. there exist a parameterless alternative
4331-
//
4332-
// Then, pick the parameterless alternative.
4333-
// See tests/pos/i10715-scala and tests/pos/i10715-java.
4334-
4335-
/** Constructs an "ambiguous overload" error */
4336-
def errorAmbiguous =
4337-
val remainingDenots = altDenots.filter(denot => ambiAlts.contains(altRef(denot)))
4338-
val addendum =
4339-
if ambiAlts.exists(!_.symbol.exists) then
4340-
i"""|
4341-
|
4342-
|Note: Overloaded definitions introduced by refinements cannot be resolved"""
4343-
else ""
4344-
errorTree(tree, AmbiguousOverload(tree, remainingDenots, pt, addendum))
4345-
end errorAmbiguous
4346-
4347-
if tree.tpe.isErroneous || pt.isErroneous then
4348-
tree.withType(UnspecifiedErrorType)
4349-
else
4350-
pt match
4351-
case _: FunProto =>
4352-
errorAmbiguous
4353-
case _ =>
4354-
tryParameterless(alts)(errorAmbiguous)
4355-
4356-
end match
4309+
case alt :: Nil =>
4310+
readaptSimplified(tree.withType(alt))
4311+
case Nil =>
4312+
// If no alternative matches, there are still two ways to recover:
4313+
// 1. If context is an application, try to insert an apply or implicit
4314+
// 2. If context is not an application, pick an alternative that does
4315+
// not take parameters.
4316+
def errorNoMatch = errorTree(tree, NoMatchingOverload(altDenots, pt))
4317+
4318+
pt match
4319+
case pt: FunOrPolyProto if pt.applyKind != ApplyKind.Using =>
4320+
// insert apply or convert qualifier, but only for a regular application
4321+
tryInsertApplyOrImplicit(tree, pt, locked)(errorNoMatch)
4322+
case _ =>
4323+
tryParameterless(alts)(errorNoMatch)
4324+
case ambiAlts =>
4325+
// If there are ambiguous alternatives, and:
4326+
// 1. the types aren't erroneous
4327+
// 2. the expected type is not a function type
4328+
// 3. there exists a parameterless alternative
4329+
//
4330+
// Then, pick the parameterless alternative. See tests/pos/i10715-*
4331+
4332+
/** Constructs an "ambiguous overload" error */
4333+
def errorAmbiguous =
4334+
val remainingDenots = altDenots.filter(denot => ambiAlts.contains(altRef(denot)))
4335+
val addendum =
4336+
if ambiAlts.exists(!_.symbol.exists) then
4337+
i"""|
4338+
|
4339+
|Note: Overloaded definitions introduced by refinements cannot be resolved"""
4340+
else ""
4341+
errorTree(tree, AmbiguousOverload(tree, remainingDenots, pt, addendum))
4342+
4343+
pt match
4344+
case pt if tree.tpe.isErroneous || pt.isErroneous =>
4345+
tree.withType(UnspecifiedErrorType)
4346+
case _: FunProto =>
4347+
errorAmbiguous
4348+
case _ =>
4349+
tryParameterless(alts)(errorAmbiguous)
43574350
end adaptOverloaded
43584351

43594352
def adaptToArgs(wtp: Type, pt: FunProto): Tree = wtp match {

0 commit comments

Comments
 (0)