Skip to content

Commit b7f02df

Browse files
committed
Early return from resolveOverloaded in case arguments are erroneous
Fixes #9344 Fixes #10983
1 parent 141bf9e commit b7f02df

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

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

+32-27
Original file line numberDiff line numberDiff line change
@@ -1945,35 +1945,40 @@ trait Applications extends Compatibility {
19451945
case _ => false
19461946

19471947
record("resolveOverloaded.narrowedApplicable", candidates.length)
1948-
val found = narrowMostSpecific(candidates)
1949-
if (found.length <= 1) found
1948+
if pt.isErroneous then
1949+
// `pt` might have become erroneous by typing arguments of FunProtos.
1950+
// If `pt` is erroneous, don't try to go further; report the error in `pt` instead.
1951+
candidates
19501952
else
1951-
val deepPt = pt.deepenProto
1952-
deepPt match
1953-
case pt @ FunProto(_, resType: FunProto) =>
1954-
// try to narrow further with snd argument list
1955-
resolveMapped(candidates, skipParamClause(pt.typedArgs().tpes), resType)
1956-
case _ =>
1957-
// prefer alternatives that need no eta expansion
1958-
val noCurried = alts.filter(!resultIsMethod(_))
1959-
val noCurriedCount = noCurried.length
1960-
if noCurriedCount == 1 then
1961-
noCurried
1962-
else if noCurriedCount > 1 && noCurriedCount < alts.length then
1963-
resolveOverloaded1(noCurried, pt)
1964-
else
1965-
// prefer alternatves that match without default parameters
1966-
val noDefaults = alts.filter(!_.symbol.hasDefaultParams)
1967-
val noDefaultsCount = noDefaults.length
1968-
if noDefaultsCount == 1 then
1969-
noDefaults
1970-
else if noDefaultsCount > 1 && noDefaultsCount < alts.length then
1971-
resolveOverloaded1(noDefaults, pt)
1972-
else if deepPt ne pt then
1973-
// try again with a deeper known expected type
1974-
resolveOverloaded1(alts, deepPt)
1953+
val found = narrowMostSpecific(candidates)
1954+
if found.length <= 1 then found
1955+
else
1956+
val deepPt = pt.deepenProto
1957+
deepPt match
1958+
case pt @ FunProto(_, resType: FunProto) =>
1959+
// try to narrow further with snd argument list
1960+
resolveMapped(candidates, skipParamClause(pt.typedArgs().tpes), resType)
1961+
case _ =>
1962+
// prefer alternatives that need no eta expansion
1963+
val noCurried = alts.filter(!resultIsMethod(_))
1964+
val noCurriedCount = noCurried.length
1965+
if noCurriedCount == 1 then
1966+
noCurried
1967+
else if noCurriedCount > 1 && noCurriedCount < alts.length then
1968+
resolveOverloaded1(noCurried, pt)
19751969
else
1976-
candidates
1970+
// prefer alternatves that match without default parameters
1971+
val noDefaults = alts.filter(!_.symbol.hasDefaultParams)
1972+
val noDefaultsCount = noDefaults.length
1973+
if noDefaultsCount == 1 then
1974+
noDefaults
1975+
else if noDefaultsCount > 1 && noDefaultsCount < alts.length then
1976+
resolveOverloaded1(noDefaults, pt)
1977+
else if deepPt ne pt then
1978+
// try again with a deeper known expected type
1979+
resolveOverloaded1(alts, deepPt)
1980+
else
1981+
candidates
19771982
}
19781983
end resolveOverloaded1
19791984

tests/neg/i9344.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
object Test {
3+
val I1: Int = 0 * * * 8 * 1 - 1 + 1 + // error
4+
}

0 commit comments

Comments
 (0)