Skip to content

Commit 3c1ff9a

Browse files
authored
Merge pull request #197 from scala/backport-lts-3.3-22356
Backport "Only check logicalOwners for methods, and not for classes, when looking for proxies" to 3.3 LTS
2 parents 1428f0f + 2881275 commit 3c1ff9a

File tree

16 files changed

+33
-301
lines changed

16 files changed

+33
-301
lines changed

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

+10
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

compiler/src/dotty/tools/dotc/transform/Dependencies.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract class Dependencies(root: ast.tpd.Tree, @constructorOnly rootContext: Co
2929
def tracked: Iterable[Symbol] = free.keys
3030

3131
/** The outermost class that captures all free variables of a function
32-
* that are captured by enclosinh classes (this means that the function could
32+
* that are captured by enclosing classes (this means that the function could
3333
* be placed in that class without having to add more environment parameters)
3434
*/
3535
def logicalOwner: collection.Map[Symbol, Symbol] = logicOwner

compiler/src/dotty/tools/dotc/transform/LambdaLift.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ object LambdaLift:
127127

128128
private def proxy(sym: Symbol)(using Context): Symbol = {
129129
def liftedEnclosure(sym: Symbol) =
130-
deps.logicalOwner.getOrElse(sym, sym.enclosure)
130+
if sym.is(Method)
131+
then deps.logicalOwner.getOrElse(sym, sym.enclosure)
132+
else sym.enclosure
131133
def searchIn(enclosure: Symbol): Symbol = {
132134
if (!enclosure.exists) {
133135
def enclosures(encl: Symbol): List[Symbol] =

compiler/test/dotc/neg-best-effort-pickling.excludelist

-23
This file was deleted.

compiler/test/dotc/neg-best-effort-unpickling.excludelist

-17
This file was deleted.

compiler/test/dotc/pos-test-pickling.blacklist

-120
This file was deleted.

compiler/test/dotc/pos-test-pickling.excludelist

+3
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,6 @@ hylolib
141141

142142
# typecheckErrors method unpickling
143143
i21415.scala
144+
145+
# LTS specific
146+
i21390.TrieMap.scala

compiler/test/dotc/run-test-pickling.blacklist

-52
This file was deleted.

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

+3-19
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

-14
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

-9
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

-29
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-
)

tests/pos-custom-args/captures/setup/a_1.scala

-6
This file was deleted.

tests/pos-custom-args/captures/setup/b_1.scala

-5
This file was deleted.

tests/pos-custom-args/captures/setup/b_2.scala

-5
This file was deleted.

0 commit comments

Comments
 (0)