Skip to content

Commit f1091e8

Browse files
authored
Merge pull request #8034 from dotty-staging/fix-#8032
Fix #8032: Make import suggestions less chatty
2 parents 619f951 + b4401bc commit f1091e8

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,17 @@ trait ImportSuggestions with
148148
System.currentTimeMillis < deadLine
149149
&& {
150150
given Context = ctx.fresh.setExploreTyperState()
151-
pt match
152-
case pt: ViewProto => pt.isMatchedBy(ref)
153-
case _ => normalize(ref, pt) <:< pt
151+
def test(pt: Type): Boolean = pt match
152+
case ViewProto(argType, OrType(rt1, rt2)) =>
153+
// Union types do not constrain results, since comparison with a union
154+
// type on the right might lose information. See ProtoTypes.disregardProto.
155+
// To regain precision, test both sides separately.
156+
test(ViewProto(argType, rt1)) || test(ViewProto(argType, rt2))
157+
case pt: ViewProto =>
158+
pt.isMatchedBy(ref)
159+
case _ =>
160+
normalize(ref, pt) <:< pt
161+
test(pt)
154162
}
155163

156164
/** Test whether a full given term can be synthesized that matches

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

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ object ProtoTypes {
6161

6262
private def disregardProto(pt: Type)(implicit ctx: Context): Boolean = pt.dealias match {
6363
case _: OrType => true
64+
// Don't constrain results with union types, since comparison with a union
65+
// type on the right might commit too early into one side.
6466
case pt => pt.isRef(defn.UnitClass)
6567
}
6668

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

+1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ trait TypeAssigner {
283283
|Note that `$name` is treated as an infix operator in Scala 3.
284284
|If you do not want that, insert a `;` or empty line in front
285285
|or drop any spaces behind the operator."""
286+
else if qualType.isBottomType then ""
286287
else
287288
var add = importSuggestionAddendum(
288289
ViewProto(qualType.widen,

tests/neg/i8032.check

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i8032.scala:1:15 --------------------------------------------------------------
2+
1 |val x: 1 | 2 = 3 // error
3+
| ^
4+
| Found: (3 : Int)
5+
| Required: (1 : Int) | (2 : Int)
6+
-- [E008] Member Not Found Error: tests/neg/i8032.scala:3:12 -----------------------------------------------------------
7+
3 |val y = ???.map // error
8+
| ^^^^^^^
9+
| value map is not a member of Nothing

tests/neg/i8032.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
val x: 1 | 2 = 3 // error
2+
3+
val y = ???.map // error

0 commit comments

Comments
 (0)