Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
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
36 changes: 14 additions & 22 deletions src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ self =>
case _ => t
}

/** Create tree representing (unencoded) binary operation expression or pattern. */
/** Create tree representing (unencoded) binary operation expression or pattern. Pos set by caller. */
def makeBinop(isExpr: Boolean, left: Tree, op: TermName, right: Tree, opPos: Position, targs: List[Tree] = Nil): Tree = {
require(isExpr || targs.isEmpty || targs.exists(_.isErroneous),
s"Incompatible args to makeBinop: !isExpr but targs=$targs")
Expand All @@ -941,42 +941,35 @@ self =>
val pos = (opPos union t.pos) makeTransparentIf rightAssoc
val sel = atPos(pos)(Select(stripParens(t), op.encode))
if (targs.isEmpty) sel
else {
/* if it's right-associative, `targs` are between `op` and `t` so make the pos transparent */
else
// if it's right-associative, (deprecated) `targs` are between `op` and `t` so make the pos transparent
atPos((pos union targs.last.pos) makeTransparentIf rightAssoc) {
TypeApply(sel, targs)
}
}
}
def mkNamed(args: List[Tree]) = if (!isExpr) args else
args.map(treeInfo.assignmentToMaybeNamedArg(_))
.tap(res => if (currentRun.isScala3 && args.lengthCompare(1) == 0 && (args.head ne res.head))
deprecationWarning(args.head.pos.point, "named argument is deprecated for infix syntax", since="2.13.16"))
var isMultiarg = false
val arguments = right match {
def arguments(arg: Tree) = arg match {
case Parens(Nil) => literalUnit :: Nil
case Parens(args @ (_ :: Nil)) => mkNamed(args)
case Parens(args) => isMultiarg = true ; mkNamed(args)
case _ => right :: Nil
case _ => arg :: Nil
}
def mkApply(fun: Tree, args: List[Tree]) = {
val apply = Apply(fun, args).updateAttachment(InfixAttachment)
if (isMultiarg) apply.updateAttachment(MultiargInfixAttachment)
apply
}
if (isExpr) {
if (rightAssoc) {
import symtab.Flags._
val x = freshTermName(nme.RIGHT_ASSOC_OP_PREFIX)
val liftedArg = atPos(left.pos) {
ValDef(Modifiers(FINAL | SYNTHETIC | ARTIFACT), x, TypeTree(), stripParens(left))
}
val apply = mkApply(mkSelection(right), List(Ident(x) setPos left.pos.focus))
Block(liftedArg :: Nil, apply)
} else
mkApply(mkSelection(left), arguments)
} else
mkApply(Ident(op.encode), stripParens(left) :: arguments)
if (isExpr)
if (rightAssoc)
mkApply(mkSelection(right), arguments(left)).updateAttachment(RightAssociative)
else
mkApply(mkSelection(left), arguments(right))
else
mkApply(Ident(op.encode), stripParens(left) :: arguments(right))
}

/** Is current ident a `*`, and is it followed by a `)` or `, )`? */
Expand Down Expand Up @@ -1014,10 +1007,9 @@ self =>
}

def checkHeadAssoc(leftAssoc: Boolean) = checkAssoc(opHead.offset, opHead.operator, leftAssoc)
def checkAssoc(offset: Offset, op: Name, leftAssoc: Boolean) = (
def checkAssoc(offset: Offset, op: Name, leftAssoc: Boolean) =
if (nme.isLeftAssoc(op) != leftAssoc)
syntaxError(offset, "left- and right-associative operators with same precedence may not be mixed", skipIt = false)
)

def finishPostfixOp(start: Int, base: List[OpInfo], opinfo: OpInfo): Tree = {
if (opinfo.targs.nonEmpty)
Expand Down Expand Up @@ -1047,7 +1039,7 @@ self =>

def reduceStack(isExpr: Boolean, base: List[OpInfo], top: Tree): Tree = {
val opPrecedence = if (isIdent) Precedence(in.name.toString) else Precedence(0)
val leftAssoc = !isIdent || (nme isLeftAssoc in.name)
val leftAssoc = !isIdent || nme.isLeftAssoc(in.name)

reduceStack(isExpr, base, top, opPrecedence, leftAssoc)
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/transform/CleanUp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ abstract class CleanUp extends Statics with Transform with ast.TreeDSL {
!elemtpt.tpe.typeSymbol.isBottomClass && !elemtpt.tpe.typeSymbol.isPrimitiveValueClass /* can happen via specialization.*/
=>
classTagEvidence.attachments.get[analyzer.MacroExpansionAttachment] match {
case Some(att) if att.expandee.symbol.name == nme.materializeClassTag && tree.isInstanceOf[ApplyToImplicitArgs] =>
case Some(att) if att.expandee.symbol.name == nme.materializeClassTag && tree.hasAttachment[AppliedToImplicitArgs.type] =>
super.transform(arg)
case _ =>
typedWithPos(tree.pos) {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/scala/tools/nsc/typechecker/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ trait Contexts { self: Analyzer with ImportTracking =>
/** A root import is never unused and always bumps context depth. (e.g scala._ / Predef._ and magic REPL imports) */
def isRootImport: Boolean = false

/** Accumulate stabilizers (PR #5999) and right-assoc locals (#5969 / #7741). See APPSELmode. */
var pendingStabilizers: List[Tree] = Nil

/** Types for which implicit arguments are currently searched */
Expand Down
16 changes: 9 additions & 7 deletions src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import scala.annotation._
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.reflect.internal.util.CodeAction
import scala.tools.nsc.Reporting.WarningCategory
import scala.tools.nsc.Reporting.WarningCategory, WarningCategory._
import scala.tools.nsc.settings.ScalaVersion
import scala.tools.nsc.settings.NoScalaVersion
import symtab.Flags._
Expand Down Expand Up @@ -994,11 +994,13 @@ abstract class RefChecks extends Transform {
def apply(tp: Type) = mapOver(tp).normalize
}

def checkImplicitViewOptionApply(pos: Position, fun: Tree, argss: List[List[Tree]]): Unit = if (settings.warnOptionImplicit) argss match {
case List(List(view: ApplyImplicitView)) if fun.symbol == currentRun.runDefinitions.Option_apply =>
refchecksWarning(pos, s"Suspicious application of an implicit view (${view.fun}) in the argument to Option.apply.", WarningCategory.LintOptionImplicit) // scala/bug#6567
case _ =>
}
def checkImplicitViewOptionApply(pos: Position, fun: Tree, argss: List[List[Tree]]): Unit =
if (settings.warnOptionImplicit && fun.symbol == currentRun.runDefinitions.Option_apply)
argss match {
case (((view @ Apply(coercion, _)) :: Nil) :: Nil) if view.hasAttachment[AppliedImplicitView.type] =>
refchecksWarning(pos, s"Suspicious application of an implicit view ($coercion) in the argument to Option.apply.", LintOptionImplicit) // scala/bug#6567
case _ =>
}

private def isObjectOrAnyComparisonMethod(sym: Symbol) = sym match {
case Object_eq | Object_ne | Object_== | Object_!= | Any_== | Any_!= => true
Expand Down Expand Up @@ -2074,7 +2076,7 @@ abstract class RefChecks extends Transform {
def checkImplicitlyAdaptedBlockResult(t: Tree): Unit = {
def loop(t: Tree): Unit =
t match {
case Apply(coercion, _) if t.isInstanceOf[ApplyImplicitView] =>
case Apply(coercion, _) if t.hasAttachment[AppliedImplicitView.type] =>
coercion.symbol.paramLists match {
case (p :: Nil) :: _ if p.isByNameParam => refchecksWarning(t.pos, s"Block result expression was adapted via implicit conversion (${coercion.symbol}) taking a by-name parameter; only the result was passed, not the entire block.", WarningCategory.LintBynameImplicit)
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait StdAttachments {
def macroExpanderAttachment(tree: Tree): MacroExpanderAttachment =
tree.attachments.get[MacroExpanderAttachment] getOrElse {
tree match {
case Apply(fn, _) if tree.isInstanceOf[ApplyToImplicitArgs] => macroExpanderAttachment(fn)
case Apply(fn, _) if tree.hasAttachment[AppliedToImplicitArgs.type] => macroExpanderAttachment(fn)
case _ => MacroExpanderAttachment(tree, EmptyTree)
}
}
Expand Down
Loading