File tree Expand file tree Collapse file tree 5 files changed +26
-3
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 5 files changed +26
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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,
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 1+ val x : 1 | 2 = 3 // error
2+
3+ val y = ??? .map // error
You can’t perform that action at this time.
0 commit comments