Skip to content

Commit 03ed937

Browse files
committed
Do not suggest implicits from scalajs.js.|
Now that we unpickle Scala.js unions as actual unions, these implicits are suddenly applicable in many more situations and can end up polluting error messages with implicit suggestions since they should never be used explicitly, so blacklist them from the suggestions.
1 parent f1b5f02 commit 03ed937

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package dotty.tools
22
package dotc
33
package typer
44

5+
import backend.sjs.JSDefinitions
56
import core._
67
import Contexts._, Types._, Symbols._, Names._, Decorators._, ProtoTypes._
78
import Flags._, SymDenotations._
89
import NameKinds.FlatName
910
import NameOps._
11+
import StdNames._
1012
import config.Printers.{implicits, implicitsDetailed}
1113
import util.Spans.Span
1214
import ast.{untpd, tpd}
@@ -64,6 +66,8 @@ trait ImportSuggestions:
6466
else !root.name.is(FlatName)
6567
&& !root.name.lastPart.contains('$')
6668
&& root.is(ModuleVal, butNot = JavaDefined)
69+
// The implicits in `scalajs.js.|` are implementation details and shouldn't be suggested
70+
&& !(root.name == nme.raw.BAR && ctx.settings.scalajs.value && root == JSDefinitions.jsdefn.PseudoUnionModule)
6771
}
6872

6973
def nestedRoots(site: Type)(using Context): List[Symbol] =

tests/neg-scalajs/type-mismatch.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E007] Type Mismatch Error: tests/neg-scalajs/type-mismatch.scala:6:17 ----------------------------------------------
2+
6 | val n: Int = msg // error message shouldn't mention implicits from `scalajs.js.|`
3+
| ^^^
4+
| Found: (msg : String)
5+
| Required: Int
6+
7+
longer explanation available when compiling with `-explain`

0 commit comments

Comments
 (0)