Skip to content

Commit

Permalink
Use isScala3Cross and tree.pos per review
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Jan 30, 2024
1 parent 386cde3 commit 0996ac6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
20 changes: 10 additions & 10 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
final def forArgMode(fun: Tree, mode: Mode) =
if (treeInfo.isSelfOrSuperConstrCall(fun)) mode | SCCmode else mode

def isScala3cross = currentRun.isScala3 && settings.source.value > scala.tools.nsc.settings.SpecificScalaVersion(3, 0, 0, scala.tools.nsc.settings.Final)

final val shortenImports = false

// All typechecked RHS of ValDefs for right-associative operator desugaring
Expand Down Expand Up @@ -1129,7 +1127,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
def adaptApplyInsertion(): Tree = {
val msg = s"The method `apply` is inserted. The auto insertion will be deprecated, please write `${tree.symbol.name}.apply` explicitly."
context.deprecationWarning(tree.pos, tree.symbol, msg, "2.13.13")
typed(Select(tree, nme.apply), mode, pt)
typed(atPos(tree.pos)(Select(tree, nme.apply)), mode, pt)
}

def adaptExprNotFunMode(): Tree = {
Expand All @@ -1138,7 +1136,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if (settings.isDebug && settings.explaintypes.value) explainTypes(tree.tpe, pt)
if (err ne null) context.issue(err)
if (tree.tpe.isErroneous || pt.isErroneous) setError(tree)
else if (isScala3cross && isFunctionType(pt) && tree.symbol.isModule && tree.symbol.companion.isCase)
else if (currentRun.isScala3Cross && isFunctionType(pt) && tree.symbol.isModule && tree.symbol.companion.isCase)
adaptApplyInsertion()
else adaptMismatchedSkolems()
}
Expand Down Expand Up @@ -5373,12 +5371,14 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
else context.javaFindMember(cls.typeOfThis, name, s => s.isStaticMember || s.isStaticModule)._2

// If they try C.tupled, make it (C.apply _).tupled
def fixUpCaseTupled(qual: Tree, name: Name, mode: Mode): Tree =
if (qual.symbol != null && isScala3cross && qual.symbol.isModule && qual.symbol.companion.isCase &&
def fixUpCaseTupled(tree: Tree, qual: Tree, name: Name, mode: Mode): Tree =
if (qual.symbol != null && currentRun.isScala3Cross && qual.symbol.isModule && qual.symbol.companion.isCase &&
context.undetparams.isEmpty && fixableFunctionMembers.contains(name)) {
val t = Select(qual, nme.apply)
val t1 = typedSelect(t, qual, nme.apply)
val t2 = typed(Select(etaExpand(t1, context.owner), name), mode, pt)
val t2 = {
val t = atPos(tree.pos)(Select(qual, nme.apply))
val t1 = typedSelect(t, qual, nme.apply)
typed(atPos(tree.pos)(Select(etaExpand(t1, context.owner), name)), mode, pt)
}
if (!t2.isErroneous) {
val msg = s"The method `apply` is inserted. The auto insertion will be deprecated, please write `${t2}` explicitly."
context.deprecationWarning(tree.pos, qual.symbol, msg, "2.13.13")
Expand Down Expand Up @@ -5424,7 +5424,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if ((qual1 ne qual) && !qual1.isErrorTyped)
typed(treeCopy.Select(tree, qual1, name), mode, pt).tap(checkDubiousAdaptation)
else
fixUpCaseTupled(qual, name, mode)
fixUpCaseTupled(tree, qual, name, mode)
if (!fixed.isEmpty)
return fixed
}
Expand Down
5 changes: 1 addition & 4 deletions src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,11 @@ trait Unapplies extends ast.TreeDSL {
else Default
}

private def isScala3cross =
currentRun.isScala3 && settings.source.value > scala.tools.nsc.settings.SpecificScalaVersion(3, 0, 0, scala.tools.nsc.settings.Final)

/** The module corresponding to a case class; overrides toString to show the module's name
*/
def caseModuleDef(cdef: ClassDef): ModuleDef = {
val params = constrParamss(cdef)
def inheritFromFun = !isScala3cross && !cdef.mods.hasAbstractFlag && cdef.tparams.isEmpty && (params match {
def inheritFromFun = !currentRun.isScala3Cross && !cdef.mods.hasAbstractFlag && cdef.tparams.isEmpty && (params match {
case List(ps) if ps.length <= MaxFunctionArity => true
case _ => false
}) && applyAccess(constrMods(cdef)) != Inherit
Expand Down

0 comments on commit 0996ac6

Please sign in to comment.