Skip to content

Backport "Only check logicalOwners for methods, and not for classes, when looking for proxies" to 3.3 LTS #197

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 2 commits into from
Apr 3, 2025
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
10 changes: 10 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ class TypeUtils:
case mt: MethodType => mt.isImplicitMethod || mt.resType.takesImplicitParams
case _ => false

/** Is this a type deriving only from transparent classes?
* @param traitOnly if true, all class symbols must be transparent traits
*/
def isTransparent(traitOnly: Boolean = false)(using Context): Boolean = self match
case AndType(tp1, tp2) =>
tp1.isTransparent(traitOnly) && tp2.isTransparent(traitOnly)
case _ =>
val cls = self.underlyingClassRef(refinementOK = false).typeSymbol
cls.isTransparentClass && (!traitOnly || cls.is(Trait))

/** The constructors of this type that are applicable to `argTypes`, without needing
* an implicit conversion. Curried constructors are always excluded.
* @param adaptVarargs if true, allow a constructor with just a varargs argument to
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class Dependencies(root: ast.tpd.Tree, @constructorOnly rootContext: Co
def tracked: Iterable[Symbol] = free.keys

/** The outermost class that captures all free variables of a function
* that are captured by enclosinh classes (this means that the function could
* that are captured by enclosing classes (this means that the function could
* be placed in that class without having to add more environment parameters)
*/
def logicalOwner: collection.Map[Symbol, Symbol] = logicOwner
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/LambdaLift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ object LambdaLift:

private def proxy(sym: Symbol)(using Context): Symbol = {
def liftedEnclosure(sym: Symbol) =
deps.logicalOwner.getOrElse(sym, sym.enclosure)
if sym.is(Method)
then deps.logicalOwner.getOrElse(sym, sym.enclosure)
else sym.enclosure
def searchIn(enclosure: Symbol): Symbol = {
if (!enclosure.exists) {
def enclosures(encl: Symbol): List[Symbol] =
Expand Down
23 changes: 0 additions & 23 deletions compiler/test/dotc/neg-best-effort-pickling.excludelist

This file was deleted.

17 changes: 0 additions & 17 deletions compiler/test/dotc/neg-best-effort-unpickling.excludelist

This file was deleted.

120 changes: 0 additions & 120 deletions compiler/test/dotc/pos-test-pickling.blacklist

This file was deleted.

3 changes: 3 additions & 0 deletions compiler/test/dotc/pos-test-pickling.excludelist
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,6 @@ hylolib

# typecheckErrors method unpickling
i21415.scala

# LTS specific
i21390.TrieMap.scala
52 changes: 0 additions & 52 deletions compiler/test/dotc/run-test-pickling.blacklist

This file was deleted.

22 changes: 3 additions & 19 deletions presentation-compiler/src/main/dotty/tools/pc/HoverProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ object HoverProvider:
case (symbol, tpe, _) :: _
if symbol.name == nme.selectDynamic || symbol.name == nme.applyDynamic =>
fallbackToDynamics(path, printer, contentType)
case symbolTpes @ ((symbol, tpe, None) :: _) =>
case symbolTpes @ ((symbol, tpe, _) :: _) =>
val exprTpw = tpe.widenTermRefExpr.deepDealias
val hoverString =
tpw match
Expand Down Expand Up @@ -153,21 +153,6 @@ object HoverProvider:
case _ =>
ju.Optional.empty().nn
end match
case (_, tpe, Some(namedTupleArg)) :: _ =>
val exprTpw = tpe.widenTermRefExpr.deepDealias
printer.expressionType(exprTpw) match
case Some(tpe) =>
ju.Optional.of(
new ScalaHover(
expressionType = Some(tpe),
symbolSignature = Some(s"$namedTupleArg: $tpe"),
docstring = None,
forceExpressionType = false,
contextInfo = printer.getUsedRenamesInfo,
contentType = contentType
)
).nn
case _ => ju.Optional.empty().nn
end match
end if
end hover
Expand All @@ -183,7 +168,7 @@ object HoverProvider:
case SelectDynamicExtractor(sel, n, name, rest) =>
def findRefinement(tp: Type): Option[HoverSignature] =
tp match
case RefinedType(_, refName, tpe) if (name == refName.toString() || refName.toString() == nme.Fields.toString()) =>
case RefinedType(_, refName, tpe) if name == refName.toString() =>
val resultType =
rest match
case Select(_, asInstanceOf) :: TypeApply(_, List(tpe)) :: _ if asInstanceOf == nme.asInstanceOfPM =>
Expand All @@ -196,8 +181,7 @@ object HoverProvider:
else printer.tpe(resultType)

val valOrDef =
if refName.toString() == nme.Fields.toString() then ""
else if n == nme.selectDynamic && !tpe.isInstanceOf[ExprType]
if n == nme.selectDynamic && !tpe.isInstanceOf[ExprType]
then "val "
else "def "

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,6 @@ object MetalsInteractive:
case _ =>
Nil

// Handle select on named tuples
case (Apply(Apply(TypeApply(fun, List(t1, t2)), List(ddef)), List(Literal(Constant(i: Int))))) :: _
if fun.symbol.exists && fun.symbol.name == nme.apply &&
fun.symbol.owner.exists && fun.symbol.owner == getModuleIfDefined("scala.NamedTuple").moduleClass =>
def getIndex(t: Tree): Option[Type] =
t.tpe.dealias match
case AppliedType(_, args) => args.get(i)
case _ => None
val name = getIndex(t1) match
case Some(c: ConstantType) => c.value.stringValue
case _ => ""
val tpe = getIndex(t2).getOrElse(NoType)
List((ddef.symbol, tpe, Some(name)))

case path @ head :: tail =>
if head.symbol.is(Exported) then
val sym = head.symbol.sourceSymbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,3 @@ class PcDefinitionSuite extends BasePcDefinitionSuite:
|val a = MyIntOut(1).un@@even
|""".stripMargin,
)

@Test def `named-tuples` =
check(
"""|import scala.language.experimental.namedTuples
|
|val <<foo>> = (name = "Bob", age = 42, height = 1.9d)
|val foo_name = foo.na@@me
|""".stripMargin
)
Original file line number Diff line number Diff line change
Expand Up @@ -718,32 +718,3 @@ class HoverTermSuite extends BaseHoverSuite:
"""def ???: Nothing""".stripMargin.hover
)

@Test def `named-tuples`: Unit =
check(
"""import scala.language.experimental.namedTuples
|
|val foo = (name = "Bob", age = 42, height = 1.9d)
|val foo_name = foo.na@@me
|""".stripMargin,
"name: String".hover
)

@Test def `named-tuples2`: Unit =
check(
"""|import scala.language.experimental.namedTuples
|
|import NamedTuple.*
|
|class NamedTupleSelectable extends Selectable {
| type Fields <: AnyNamedTuple
| def selectDynamic(name: String): Any = ???
|}
|
|val person = new NamedTupleSelectable {
| type Fields = (name: String, city: String)
|}
|
|val person_name = person.na@@me
|""".stripMargin,
"name: String".hover
)
6 changes: 0 additions & 6 deletions tests/pos-custom-args/captures/setup/a_1.scala

This file was deleted.

5 changes: 0 additions & 5 deletions tests/pos-custom-args/captures/setup/b_1.scala

This file was deleted.

5 changes: 0 additions & 5 deletions tests/pos-custom-args/captures/setup/b_2.scala

This file was deleted.

Loading
Loading