Skip to content

Commit da1e073

Browse files
committed
Vertical alignment in adaptOverloaded
1 parent 577721f commit da1e073

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
@@ -4370,54 +4370,47 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43704370
val alts = altDenots.map(altRef)
43714371

43724372
resolveOverloaded(alts, pt) match
4373-
case alt :: Nil =>
4374-
readaptSimplified(tree.withType(alt))
4375-
case Nil =>
4376-
// If no alternative matches, there are still two ways to recover:
4377-
// 1. If context is an application, try to insert an apply or implicit
4378-
// 2. If context is not an application, pick a alternative that does
4379-
// not take parameters.
4380-
4381-
def errorNoMatch = errorTree(tree, NoMatchingOverload(altDenots, pt))
4382-
4383-
pt match
4384-
case pt: FunOrPolyProto if pt.applyKind != ApplyKind.Using =>
4385-
// insert apply or convert qualifier, but only for a regular application
4386-
tryInsertApplyOrImplicit(tree, pt, locked)(errorNoMatch)
4387-
case _ =>
4388-
tryParameterless(alts)(errorNoMatch)
4389-
4390-
case ambiAlts =>
4391-
// If there are ambiguous alternatives, and:
4392-
// 1. the types aren't erroneous
4393-
// 2. the expected type is not a function type
4394-
// 3. there exist a parameterless alternative
4395-
//
4396-
// Then, pick the parameterless alternative.
4397-
// See tests/pos/i10715-scala and tests/pos/i10715-java.
4398-
4399-
/** Constructs an "ambiguous overload" error */
4400-
def errorAmbiguous =
4401-
val remainingDenots = altDenots.filter(denot => ambiAlts.contains(altRef(denot)))
4402-
val addendum =
4403-
if ambiAlts.exists(!_.symbol.exists) then
4404-
i"""|
4405-
|
4406-
|Note: Overloaded definitions introduced by refinements cannot be resolved"""
4407-
else ""
4408-
errorTree(tree, AmbiguousOverload(tree, remainingDenots, pt, addendum))
4409-
end errorAmbiguous
4410-
4411-
if tree.tpe.isErroneous || pt.isErroneous then
4412-
tree.withType(UnspecifiedErrorType)
4413-
else
4414-
pt match
4415-
case _: FunProto =>
4416-
errorAmbiguous
4417-
case _ =>
4418-
tryParameterless(alts)(errorAmbiguous)
4419-
4420-
end match
4373+
case alt :: Nil =>
4374+
readaptSimplified(tree.withType(alt))
4375+
case Nil =>
4376+
// If no alternative matches, there are still two ways to recover:
4377+
// 1. If context is an application, try to insert an apply or implicit
4378+
// 2. If context is not an application, pick an alternative that does
4379+
// not take parameters.
4380+
def errorNoMatch = errorTree(tree, NoMatchingOverload(altDenots, pt))
4381+
4382+
pt match
4383+
case pt: FunOrPolyProto if pt.applyKind != ApplyKind.Using =>
4384+
// insert apply or convert qualifier, but only for a regular application
4385+
tryInsertApplyOrImplicit(tree, pt, locked)(errorNoMatch)
4386+
case _ =>
4387+
tryParameterless(alts)(errorNoMatch)
4388+
case ambiAlts =>
4389+
// If there are ambiguous alternatives, and:
4390+
// 1. the types aren't erroneous
4391+
// 2. the expected type is not a function type
4392+
// 3. there exists a parameterless alternative
4393+
//
4394+
// Then, pick the parameterless alternative. See tests/pos/i10715-*
4395+
4396+
/** Constructs an "ambiguous overload" error */
4397+
def errorAmbiguous =
4398+
val remainingDenots = altDenots.filter(denot => ambiAlts.contains(altRef(denot)))
4399+
val addendum =
4400+
if ambiAlts.exists(!_.symbol.exists) then
4401+
i"""|
4402+
|
4403+
|Note: Overloaded definitions introduced by refinements cannot be resolved"""
4404+
else ""
4405+
errorTree(tree, AmbiguousOverload(tree, remainingDenots, pt, addendum))
4406+
4407+
pt match
4408+
case pt if tree.tpe.isErroneous || pt.isErroneous =>
4409+
tree.withType(UnspecifiedErrorType)
4410+
case _: FunProto =>
4411+
errorAmbiguous
4412+
case _ =>
4413+
tryParameterless(alts)(errorAmbiguous)
44214414
end adaptOverloaded
44224415

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

0 commit comments

Comments
 (0)