Skip to content

Fix #8032: Make import suggestions less chatty #8034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,17 @@ trait ImportSuggestions with
System.currentTimeMillis < deadLine
&& {
given Context = ctx.fresh.setExploreTyperState()
pt match
case pt: ViewProto => pt.isMatchedBy(ref)
case _ => normalize(ref, pt) <:< pt
def test(pt: Type): Boolean = pt match
case ViewProto(argType, OrType(rt1, rt2)) =>
// Union types do not constrain results, since comparison with a union
// type on the right might lose information. See ProtoTypes.disregardProto.
// To regain precision, test both sides separately.
test(ViewProto(argType, rt1)) || test(ViewProto(argType, rt2))
case pt: ViewProto =>
pt.isMatchedBy(ref)
case _ =>
normalize(ref, pt) <:< pt
test(pt)
}

/** Test whether a full given term can be synthesized that matches
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ object ProtoTypes {

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

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ trait TypeAssigner {
|Note that `$name` is treated as an infix operator in Scala 3.
|If you do not want that, insert a `;` or empty line in front
|or drop any spaces behind the operator."""
else if qualType.isBottomType then ""
else
var add = importSuggestionAddendum(
ViewProto(qualType.widen,
Expand Down
9 changes: 9 additions & 0 deletions tests/neg/i8032.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- [E007] Type Mismatch Error: tests/neg/i8032.scala:1:15 --------------------------------------------------------------
1 |val x: 1 | 2 = 3 // error
| ^
| Found: (3 : Int)
| Required: (1 : Int) | (2 : Int)
-- [E008] Member Not Found Error: tests/neg/i8032.scala:3:12 -----------------------------------------------------------
3 |val y = ???.map // error
| ^^^^^^^
| value map is not a member of Nothing
3 changes: 3 additions & 0 deletions tests/neg/i8032.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
val x: 1 | 2 = 3 // error

val y = ???.map // error