Skip to content

Commit 8a4b87e

Browse files
som-snyttWojciechMazur
authored andcommitted
Vertical alignment in adaptOverloaded
[Cherry-picked da1e073]
1 parent e7cb876 commit 8a4b87e

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

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

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

0 commit comments

Comments
 (0)