Skip to content

Commit d103d7a

Browse files
committed
bugfix: Fix issues after backporting
- remove named tuples specific parts (we anyway try to port as much as possible to avoid conflicts in the future) - add isTransparent method which was probably added in some incompatible PR
1 parent a4a9dff commit d103d7a

File tree

5 files changed

+13
-71
lines changed

5 files changed

+13
-71
lines changed

compiler/src/dotty/tools/dotc/core/TypeUtils.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ class TypeUtils:
127127
case mt: MethodType => mt.isImplicitMethod || mt.resType.takesImplicitParams
128128
case _ => false
129129

130+
/** Is this a type deriving only from transparent classes?
131+
* @param traitOnly if true, all class symbols must be transparent traits
132+
*/
133+
def isTransparent(traitOnly: Boolean = false)(using Context): Boolean = self match
134+
case AndType(tp1, tp2) =>
135+
tp1.isTransparent(traitOnly) && tp2.isTransparent(traitOnly)
136+
case _ =>
137+
val cls = self.underlyingClassRef(refinementOK = false).typeSymbol
138+
cls.isTransparentClass && (!traitOnly || cls.is(Trait))
139+
130140
/** The constructors of this type that are applicable to `argTypes`, without needing
131141
* an implicit conversion. Curried constructors are always excluded.
132142
* @param adaptVarargs if true, allow a constructor with just a varargs argument to

presentation-compiler/src/main/dotty/tools/pc/HoverProvider.scala

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ object HoverProvider:
107107
case (symbol, tpe, _) :: _
108108
if symbol.name == nme.selectDynamic || symbol.name == nme.applyDynamic =>
109109
fallbackToDynamics(path, printer, contentType)
110-
case symbolTpes @ ((symbol, tpe, None) :: _) =>
110+
case symbolTpes @ ((symbol, tpe, _) :: _) =>
111111
val exprTpw = tpe.widenTermRefExpr.deepDealias
112112
val hoverString =
113113
tpw match
@@ -153,21 +153,6 @@ object HoverProvider:
153153
case _ =>
154154
ju.Optional.empty().nn
155155
end match
156-
case (_, tpe, Some(namedTupleArg)) :: _ =>
157-
val exprTpw = tpe.widenTermRefExpr.deepDealias
158-
printer.expressionType(exprTpw) match
159-
case Some(tpe) =>
160-
ju.Optional.of(
161-
new ScalaHover(
162-
expressionType = Some(tpe),
163-
symbolSignature = Some(s"$namedTupleArg: $tpe"),
164-
docstring = None,
165-
forceExpressionType = false,
166-
contextInfo = printer.getUsedRenamesInfo,
167-
contentType = contentType
168-
)
169-
).nn
170-
case _ => ju.Optional.empty().nn
171156
end match
172157
end if
173158
end hover
@@ -183,7 +168,7 @@ object HoverProvider:
183168
case SelectDynamicExtractor(sel, n, name, rest) =>
184169
def findRefinement(tp: Type): Option[HoverSignature] =
185170
tp match
186-
case RefinedType(_, refName, tpe) if (name == refName.toString() || refName.toString() == nme.Fields.toString()) =>
171+
case RefinedType(_, refName, tpe) if name == refName.toString() =>
187172
val resultType =
188173
rest match
189174
case Select(_, asInstanceOf) :: TypeApply(_, List(tpe)) :: _ if asInstanceOf == nme.asInstanceOfPM =>
@@ -196,8 +181,7 @@ object HoverProvider:
196181
else printer.tpe(resultType)
197182

198183
val valOrDef =
199-
if refName.toString() == nme.Fields.toString() then ""
200-
else if n == nme.selectDynamic && !tpe.isInstanceOf[ExprType]
184+
if n == nme.selectDynamic && !tpe.isInstanceOf[ExprType]
201185
then "val "
202186
else "def "
203187

presentation-compiler/src/main/dotty/tools/pc/MetalsInteractive.scala

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,6 @@ object MetalsInteractive:
203203
case _ =>
204204
Nil
205205

206-
// Handle select on named tuples
207-
case (Apply(Apply(TypeApply(fun, List(t1, t2)), List(ddef)), List(Literal(Constant(i: Int))))) :: _
208-
if fun.symbol.exists && fun.symbol.name == nme.apply &&
209-
fun.symbol.owner.exists && fun.symbol.owner == getModuleIfDefined("scala.NamedTuple").moduleClass =>
210-
def getIndex(t: Tree): Option[Type] =
211-
t.tpe.dealias match
212-
case AppliedType(_, args) => args.get(i)
213-
case _ => None
214-
val name = getIndex(t1) match
215-
case Some(c: ConstantType) => c.value.stringValue
216-
case _ => ""
217-
val tpe = getIndex(t2).getOrElse(NoType)
218-
List((ddef.symbol, tpe, Some(name)))
219-
220206
case path @ head :: tail =>
221207
if head.symbol.is(Exported) then
222208
val sym = head.symbol.sourceSymbol

presentation-compiler/test/dotty/tools/pc/tests/definition/PcDefinitionSuite.scala

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,3 @@ class PcDefinitionSuite extends BasePcDefinitionSuite:
504504
|val a = MyIntOut(1).un@@even
505505
|""".stripMargin,
506506
)
507-
508-
@Test def `named-tuples` =
509-
check(
510-
"""|import scala.language.experimental.namedTuples
511-
|
512-
|val <<foo>> = (name = "Bob", age = 42, height = 1.9d)
513-
|val foo_name = foo.na@@me
514-
|""".stripMargin
515-
)

presentation-compiler/test/dotty/tools/pc/tests/hover/HoverTermSuite.scala

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -718,32 +718,3 @@ class HoverTermSuite extends BaseHoverSuite:
718718
"""def ???: Nothing""".stripMargin.hover
719719
)
720720

721-
@Test def `named-tuples`: Unit =
722-
check(
723-
"""import scala.language.experimental.namedTuples
724-
|
725-
|val foo = (name = "Bob", age = 42, height = 1.9d)
726-
|val foo_name = foo.na@@me
727-
|""".stripMargin,
728-
"name: String".hover
729-
)
730-
731-
@Test def `named-tuples2`: Unit =
732-
check(
733-
"""|import scala.language.experimental.namedTuples
734-
|
735-
|import NamedTuple.*
736-
|
737-
|class NamedTupleSelectable extends Selectable {
738-
| type Fields <: AnyNamedTuple
739-
| def selectDynamic(name: String): Any = ???
740-
|}
741-
|
742-
|val person = new NamedTupleSelectable {
743-
| type Fields = (name: String, city: String)
744-
|}
745-
|
746-
|val person_name = person.na@@me
747-
|""".stripMargin,
748-
"name: String".hover
749-
)

0 commit comments

Comments
 (0)