Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7d8ebee

Browse files
committed
rejigger
1 parent4ad324d commit7d8ebee

File tree

7 files changed

+95
-28
lines changed

7 files changed

+95
-28
lines changed

‎src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ self =>
902902
case _=> t
903903
}
904904

905-
/** Create tree representing (unencoded) binary operation expression or pattern.*/
905+
/** Create tree representing (unencoded) binary operation expression or pattern.Pos set by caller.*/
906906
defmakeBinop(isExpr:Boolean,left:Tree,op:TermName,right:Tree,opPos:Position,targs:List[Tree]=Nil):Tree= {
907907
require(isExpr|| targs.isEmpty|| targs.exists(_.isErroneous),
908908
s"Incompatible args to makeBinop: !isExpr but targs=$targs")
@@ -913,12 +913,11 @@ self =>
913913
valpos= (opPos union t.pos) makeTransparentIf rightAssoc
914914
valsel= atPos(pos)(Select(stripParens(t), op.encode))
915915
if (targs.isEmpty) sel
916-
else {
917-
/* if it's right-associative, `targs` are between `op` and `t` so make the pos transparent*/
916+
else
917+
// if it's right-associative, `targs` are between `op` and `t` so make the pos transparent
918918
atPos((pos union targs.last.pos) makeTransparentIf rightAssoc) {
919919
TypeApply(sel, targs)
920920
}
921-
}
922921
}
923922
defmkNamed(args:List[Tree])=if (isExpr) args.map(treeInfo.assignmentToMaybeNamedArg)else args
924923
varisMultiarg=false

‎src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import scala.util.chaining._
2323
importmutable.ListBuffer
2424
importsymtab.Flags._
2525
importMode._
26+
importPartialFunction.cond
2627

2728
/** A provider of methods to assign types to trees.
2829
*
@@ -5083,25 +5084,17 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
50835084
// The enclosing context may be case c @ C(_) => or val c @ C(_) = v.
50845085
tree1 modifyType (_.finalResultType)
50855086
tree1
5086-
case tree1@Apply(fun1, arg1::Nil)if tree.hasAttachment[RightAssociative.type]=>
5087-
tree.removeAttachment[RightAssociative.type]
5087+
case tree1@Apply(fun1, arg1::Nil)if!phase.erasedTypes&& tree.hasAttachment[RightAssociative.type]=>
50885088
fun1.tpematch {
50895089
// fix evaluation order of `x op_: y` if necessary to `{ val tmp = x ; y.op_:(tmp) }`
50905090
caseMethodType(p::Nil, _)if!tree1.isErroneous&&!p.isByNameParam&& (!treeInfo.isStableIdentifier(arg1, allowVolatile=false)||!treeInfo.isExprSafeToInline(arg1))=>
5091-
importsymtab.Flags._
5092-
valtmp= freshTermName(nme.RIGHT_ASSOC_OP_PREFIX)
5093-
valvalSym= context.owner.newValue(tmp, arg1.pos.focus,FINAL|SYNTHETIC|ARTIFACT)
5094-
valrhs= arg1.changeOwner(context.owner-> valSym)
5095-
valSym.setInfo(rhs.tpe)
5096-
valliftedArg= atPos(arg1.pos) {ValDef(valSym, rhs) }
5097-
valblk=Block(
5098-
liftedArg::Nil,
5099-
treeCopy.Apply(tree1, fun1,List(Ident(valSym) setPos arg1.pos.focus)).clearType()
5100-
)
5101-
typed(blk, mode, pt)match {
5102-
case b@Block(_, res)=> res.updateAttachment(RightAssociative) ; b
5103-
case b=> b
5104-
}
5091+
valvsym= context.owner.newValue(freshTermName(nme.RIGHT_ASSOC_OP_PREFIX), arg1.pos.focus,FINAL|SYNTHETIC|ARTIFACT)
5092+
vsym.setInfo(arg1.tpe)
5093+
valvdef= atPos(arg1.pos) {ValDef(vsym, arg1) setTypeNoType }
5094+
context.pendingStabilizers::= vdef
5095+
arg1.changeOwner(context.owner-> vsym)
5096+
valarg=Ident(vsym) setType singleType(NoPrefix, vsym) setPos arg1.pos.focus
5097+
treeCopy.Apply(tree1, fun1, arg::Nil)
51055098
case _=> tree1
51065099
}
51075100
case tree1@Apply(_, args1)if settings.multiargInfix&& tree.hasAttachment[MultiargInfixAttachment.type]&& args1.lengthCompare(1)>0=>
@@ -6081,15 +6074,30 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
60816074
}
60826075
}
60836076

6077+
// Insert stabilizing ValDefs (if any) introduced during the typing of the original expression.
60846078
privatedefaddStabilizers(newStabilizers:List[Tree],expr:Tree):Tree=if (newStabilizers.isEmpty) exprelse {
60856079
devWarningIf(newStabilizers.forall(_.symbol.owner== context.owner))(s"${context.owner} -${(newStabilizers.map(vd=> (vd.symbol, vd.symbol.owner.fullNameString)), context.owner)}")
6086-
// Insert stabilizing ValDefs (if any) which might have been introduced during the typing of the original expression.
6087-
exprmatch {
6088-
caseBlock(_, res)if res.hasAttachment[RightAssociative.type]=>
6089-
runReporting.warning(res.pos,s"right-associative application requires evaluating right-to-left",WarningCategory.Other, context.owner)
6090-
case _=>
6091-
}
6092-
Block(newStabilizers.reverse, expr).setPos(expr.pos).setType(expr.tpe)
6080+
defisStab(prefix:String)(x:Tree)= cond(x) {caseValDef(_, nm, _, _)=> nm.startsWith(prefix) }
6081+
valhasStabs= newStabilizers.exists(isStab(nme.STABILIZER_PREFIX))
6082+
valhasRassocs= newStabilizers.exists(isStab(nme.RIGHT_ASSOC_OP_PREFIX))
6083+
// stabilizers are in reverse order, but re-ordered operands are in desired (left-to-right) order
6084+
valres=
6085+
if (hasStabs&& hasRassocs) {
6086+
runReporting.warning(expr.pos.focus,s"right-associative application requires right-to-left evaluation",WarningCategory.Other, context.owner)
6087+
varremaining= newStabilizers.reverse
6088+
valordered=ListBuffer.empty[Tree]
6089+
while (remaining.nonEmpty) {
6090+
val (stabs, more)= remaining.span(isStab(nme.STABILIZER_PREFIX))
6091+
ordered.addAll(stabs)
6092+
val (rassocs, rest)= more.span(isStab(nme.RIGHT_ASSOC_OP_PREFIX))
6093+
ordered.addAll(rassocs.reverse)
6094+
remaining= rest
6095+
}
6096+
ordered.toList
6097+
}
6098+
elseif (hasStabs) newStabilizers.reverse
6099+
else newStabilizers
6100+
Block(res, expr).setPos(expr.pos).setType(expr.tpe)
60936101
}
60946102

60956103
defatOwner(owner:Symbol):Typer=

‎test/files/pos/t4518.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
importlanguage.existentials
3+
4+
classBroke {
5+
6+
valtempval=newAnyRef {valroleA=newAnyRefwithBar}.roleA
7+
8+
newAnyRef {}-: tempval// when not assigning to anything, no problem
9+
valbroke_val=newAnyRef {}-: tempval// type mismatch error only when assigning
10+
11+
traitFoo[AnyRef] { }
12+
13+
traitBarextendsFoo[AnyRef] {
14+
def-:(core:AnyRef):this.typewithFoo[core.type]=thrownewException()
15+
}
16+
}

‎test/files/pos/t5073.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,13 @@ class A {
2424
defself=this
2525
defbar(x:A,y:A)= (x.self/: y.self)(1)
2626
}
27+
28+
classB {
29+
@annotation.nowarn
30+
deff(xs:List[Int])= (0/: xs) _
31+
defg= f(List(1,2,3,4))
32+
deftest= g(_+ _)
33+
}
34+
35+
// issue 11117
36+
classA2[B](valb:B) {defc:List[b.type]= b::Nil }

‎test/files/run/t1980b.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
t1980b.scala:26: warning: right-associative application requires right-to-left evaluation
2+
f(27) ##:: g(5) #:: f(42) ##:: xs
3+
^
4+
empty
5+
g5
6+
f42
7+
f27

‎test/files/run/t1980b.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// scalac: -Yrangepos
2+
//
3+
4+
importlanguage.implicitConversions
5+
importscala.util.chaining._
6+
7+
caseclassLI(n:Option[Int],rest:LI) {
8+
def##:: (elem:Cell):LI=LI(Some(elem.x),this)
9+
def#:: (s:String):LI=LI(Some(s.toInt),this)
10+
11+
caseclassCell(x:Int)
12+
objectCell {
13+
implicitdef`wrap element`(x:Int):Cell=Cell(x)
14+
}
15+
}
16+
17+
objectLI {
18+
defempty:LI=LI(None,null)
19+
}
20+
21+
// check order of evaluation with mixed stabilizers
22+
objectTestextendsApp {
23+
deff(i:Int)= i.tap(n=> println(s"f$n"))
24+
defg(i:Int)= i.toString.tap(n=> println(s"g$n"))
25+
defxs=LI.empty.tap(_=> println("empty"))
26+
f(27)##:: g(5)#:: f(42)##:: xs
27+
}

‎test/files/run/t4225e.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
t4225e.scala:19: warning: right-associative application requiresevaluatingright-to-left
1+
t4225e.scala:19: warning: right-associative application requires right-to-left evaluation
22
mkBarString andThen_: mkFoo
33
^
44
t4225e.scala:12: warning: a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp