Skip to content

Commit c7a0e66

Browse files
Opaque types are not desugared on REPL code completion
REPL code completion computes completion candidates for a given expression after typechecking it. Typechecking opaque types desugars them from `<mods> type T = Int` to `<mods> type T = T.T`. The completion relies on the position of the user's cursor in the input expression to know what part of this expression to complete. Since the cursor does not take the semantic info computed by typechecking, the cursor points to `T.T` and not to `Int` on completion request. Completion on synthetic `T.T` does not pick any candidates, which is unexpected to the user. The expected behavior is to complete on `Int`, the underlying type. This commit achieves the expected behavior by making sure opaque types are treated as ordinary types on code completion.
1 parent 165ab8c commit c7a0e66

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ object desugar {
806806
ctx.error(em"opaque type ${tdef.name} must be an alias type", tdef.sourcePos)
807807
tdef.withFlags(tdef.mods.flags &~ Opaque)
808808
}
809-
else {
809+
else if (!ctx.settings.YnoOpaqueTypes.value) {
810810
def completeForwarder(fwd: Tree) = tdef.rhs match {
811811
case LambdaTypeTree(tparams, tpt) =>
812812
val tparams1 =
@@ -828,6 +828,7 @@ object desugar {
828828
.withFlags(Synthetic | Opaque))
829829
Thicket(aliasType :: companions.toList)
830830
}
831+
else tdef.withFlags(tdef.mods.flags &~ Opaque)
831832

832833
/** The normalized name of `mdef`. This means
833834
* 1. Check that the name does not redefine a Scala core class.

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class ScalaSettings extends Settings.SettingGroup {
144144
val YcheckAllPatmat: Setting[Boolean] = BooleanSetting("-Ycheck-all-patmat", "Check exhaustivity and redundancy of all pattern matching (used for testing the algorithm)")
145145
val YretainTrees: Setting[Boolean] = BooleanSetting("-Yretain-trees", "Retain trees for top-level classes, accessible from ClassSymbol#tree")
146146
val YshowTreeIds: Setting[Boolean] = BooleanSetting("-Yshow-tree-ids", "Uniquely tag all tree nodes in debugging output.")
147+
val YnoOpaqueTypes: Setting[Boolean] = BooleanSetting("-Yno-opaque-types", "Opaque types are treated as ordinary transparent types.")
147148

148149
val YprofileEnabled: Setting[Boolean] = BooleanSetting("-Yprofile-enabled", "Enable profiling.")
149150
val YprofileDestination: Setting[String] = StringSetting("-Yprofile-destination", "file", "where to send profiling output - specify a file, default is to the console.", "")

compiler/src/dotty/tools/repl/ReplCompiler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ class ReplCompiler extends Compiler {
277277
implicit val ctx: Context = state.context.fresh
278278
.setReporter(newStoreReporter)
279279
.setSetting(state.context.settings.YstopAfter, List("frontend"))
280+
.setSetting(state.context.settings.YnoOpaqueTypes, true)
280281

281282
wrapped(expr, src, state).flatMap { pkg =>
282283
val unit = CompilationUnit(src)

0 commit comments

Comments
 (0)