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

Commit92bd67a

Browse files
committed
ApplyImplicitView is Applied attachment
1 parent66a9ac7 commit92bd67a

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import scala.annotation._
1717
importscala.collection.mutable
1818
importscala.collection.mutable.ListBuffer
1919
importscala.reflect.internal.util.CodeAction
20-
importscala.tools.nsc.Reporting.WarningCategory
20+
importscala.tools.nsc.Reporting.WarningCategory,WarningCategory._
2121
importscala.tools.nsc.settings.ScalaVersion
2222
importscala.tools.nsc.settings.NoScalaVersion
2323
importsymtab.Flags._
@@ -994,11 +994,13 @@ abstract class RefChecks extends Transform {
994994
defapply(tp:Type)= mapOver(tp).normalize
995995
}
996996

997-
defcheckImplicitViewOptionApply(pos:Position,fun:Tree,argss:List[List[Tree]]):Unit=if (settings.warnOptionImplicit) argssmatch {
998-
caseList(List(view:ApplyImplicitView))if fun.symbol== currentRun.runDefinitions.Option_apply=>
999-
refchecksWarning(pos,s"Suspicious application of an implicit view (${view.fun}) in the argument to Option.apply.",WarningCategory.LintOptionImplicit)// scala/bug#6567
1000-
case _=>
1001-
}
997+
defcheckImplicitViewOptionApply(pos:Position,fun:Tree,argss:List[List[Tree]]):Unit=
998+
if (settings.warnOptionImplicit&& fun.symbol== currentRun.runDefinitions.Option_apply)
999+
argssmatch {
1000+
case (((view@Apply(coercion, _))::Nil)::Nil)if view.hasAttachment[AppliedImplicitView.type]=>
1001+
refchecksWarning(pos,s"Suspicious application of an implicit view ($coercion) in the argument to Option.apply.",LintOptionImplicit)// scala/bug#6567
1002+
case _=>
1003+
}
10021004

10031005
privatedefisObjectOrAnyComparisonMethod(sym:Symbol)= symmatch {
10041006
caseObject_eq|Object_ne|Object_==|Object_!=|Any_==|Any_!==>true
@@ -2074,7 +2076,7 @@ abstract class RefChecks extends Transform {
20742076
defcheckImplicitlyAdaptedBlockResult(t:Tree):Unit= {
20752077
defloop(t:Tree):Unit=
20762078
tmatch {
2077-
caseApply(coercion, _)if t.isInstanceOf[ApplyImplicitView]=>
2079+
caseApply(coercion, _)if t.hasAttachment[AppliedImplicitView.type]=>
20782080
coercion.symbol.paramListsmatch {
20792081
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)
20802082
case _=>

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
12161216
if (settings.logImplicitConv.value) context.echo(tree.pos, msg)
12171217
else debuglog(msg)
12181218

1219-
valviewApplied=newApplyImplicitView(coercion,List(tree))setPostree.pos
1219+
valviewApplied=ApplyImplicitView(coercion,List(tree)).setPos(tree.pos)
12201220
valsilentContext= context.makeImplicit(context.ambiguousErrors)
12211221
valtypedView= newTyper(silentContext).typed(viewApplied, mode, pt)
12221222

@@ -1383,7 +1383,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
13831383
&&!qtpe.isError
13841384
&&!qtpe.typeSymbol.isBottomClass
13851385
&&!qtpe.isWildcard
1386-
&&!qual.isInstanceOf[ApplyImplicitView]// don't chain views
1386+
&&!qual.hasAttachment[AppliedImplicitView.type]// don't chain views
13871387
&& (context.implicitsEnabled|| context.enrichmentEnabled)
13881388
// Elaborating `context.implicitsEnabled`:
13891389
// don't try to adapt a top-level type that's the subject of an implicit search
@@ -1410,7 +1410,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
14101410
if (currentRun.isScala3&& coercion.symbol== currentRun.runDefinitions.Predef_any2stringaddMethod)
14111411
if (!currentRun.sourceFeatures.any2StringAdd)
14121412
runReporting.warning(qual.pos,s"Converting to String for concatenation is not supported in Scala 3 (or with -Xsource-features:any2stringadd).",Scala3Migration, coercion.symbol)
1413-
typedQualifier(atPos(qual.pos)(newApplyImplicitView(coercion,List(qual))))
1413+
typedQualifier(atPos(qual.pos)(ApplyImplicitView(coercion,List(qual))))
14141414
}
14151415
}
14161416
else qual
@@ -3680,8 +3680,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
36803680
valtreeInfo.Applied(_, _, argss)= appl
36813681
valneedsAdjust=
36823682
argss.find {
3683-
case (aiv:ApplyImplicitView)::Nil=>
3684-
aiv.argsmatch {
3683+
case (view@Apply(_, viewed))::Nilif view.hasAttachment[AppliedImplicitView.type]=>
3684+
viewedmatch {
36853685
caseBlock(_:: _, _)::Nil=>true
36863686
case _=>false
36873687
}
@@ -5224,9 +5224,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
52245224
fn.symbol.paramListsmatch {
52255225
case (h::Nil)::Nilif!h.isByNameParam&& (!isUserRassocArg(arg)|| needsRewrite(arg))=>
52265226
valarg1= argmatch {
5227-
caseview:ApplyImplicitViewif usesStab(view.fun)=>
5228-
newApplyImplicitView(view.fun, rewriteRightAssoc(view.args.head)::Nil)
5229-
.setType(view.tpe).setPos(view.pos)
5227+
case view@Apply(coercion, coerced::Nil)if view.hasAttachment[AppliedImplicitView.type]&& usesStab(coercion)=>
5228+
treeCopy.Apply(view, coercion, rewriteRightAssoc(coerced)::Nil)
52305229
case arg=> rewriteRightAssoc(arg)
52315230
}
52325231
treeCopy.Apply(applied, fn, arg1::Nil)
@@ -6358,8 +6357,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
63586357
// if in the midst of series of apply, possibly a qualifier was adapted, possibly an rassoc arg.
63596358
// the expression to rewrite with added stabilizers is different for each case.
63606359
valresult= adaptedmatch {
6361-
caseview:ApplyImplicitViewif shouldInsertRassocs=>
6362-
newApplyImplicitView(view.fun,addStabilizers(view.args.head)::Nil)
6360+
case view@Apply(coercion, coerced::Nil)if view.hasAttachment[AppliedImplicitView.type]&& shouldInsertRassocs=>
6361+
treeCopy.Apply(view, coercion,addStabilizers(coerced)::Nil)
63636362
case _if shouldInsertStabilizers=> addStabilizers(adapted)
63646363
case _=> adapted
63656364
}

‎src/reflect/scala/reflect/internal/Importers.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,6 @@ trait Importers { to: SymbolTable =>
382382
case from.Apply(fun, args)=> theirmatch {
383383
case_: from.ApplyToImplicitArgs=>
384384
newApplyToImplicitArgs(importTree(fun), args map importTree)
385-
case_: from.ApplyImplicitView=>
386-
newApplyImplicitView(importTree(fun), args map importTree)
387385
case _=>
388386
newApply(importTree(fun), args map importTree)
389387
}

‎src/reflect/scala/reflect/internal/StdAttachments.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,7 @@ trait StdAttachments {
188188
caseobjectRightAssociativeextendsPlainAttachment
189189
/** Arg to right associative infix application is candidate for rewriting.*/
190190
caseobjectRightAssociativeArgextendsPlainAttachment
191+
192+
/** Application is an implicit view.*/
193+
caseobjectAppliedImplicitViewextendsPlainAttachment
191194
}

‎src/reflect/scala/reflect/internal/Trees.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -809,9 +809,7 @@ trait Trees extends api.Trees {
809809
// copying trees will all too easily forget to distinguish subclasses
810810
classApplyToImplicitArgs(fun:Tree,args:List[Tree])extendsApply(fun, args)
811811

812-
// TODO remove this class, add a tree attachment to Apply to track whether implicits were involved
813-
// copying trees will all too easily forget to distinguish subclasses
814-
classApplyImplicitView(fun:Tree,args:List[Tree])extendsApply(fun, args)
812+
defApplyImplicitView(fun:Tree,args:List[Tree])=Apply(fun, args).updateAttachment(AppliedImplicitView)
815813

816814
defApplyConstructor(tpt:Tree,args:List[Tree])=Apply(Select(New(tpt), nme.CONSTRUCTOR), args)
817815

@@ -1114,7 +1112,6 @@ trait Trees extends api.Trees {
11141112
defApply(tree:Tree,fun:Tree,args:List[Tree])=
11151113
(treematch {// TODO: use a tree attachment to track whether this is an apply to implicit args or a view
11161114
case_:ApplyToImplicitArgs=>newApplyToImplicitArgs(fun, args)
1117-
case_:ApplyImplicitView=>newApplyImplicitView(fun, args)
11181115
// TODO: ApplyConstructor ???
11191116
case self.pendingSuperCall=> self.pendingSuperCall
11201117
case _=>newApply(fun, args)

‎src/reflect/scala/reflect/runtime/JavaUniverseForce.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
9393
this.BooleanParameterType
9494
this.RightAssociative
9595
this.RightAssociativeArg
96+
this.AppliedImplicitView
9697
this.noPrint
9798
this.typeDebug
9899
// inaccessible: this.posAssigner

‎src/scaladoc/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ trait ModelFactoryImplicitSupport {
192192

193193
// type the view application so we get the exact type of the result (not the formal type)
194194
valviewTree= result.tree.setType(viewSimplifiedType)
195-
valappliedTree=newApplyImplicitView(viewTree,List(Ident("<argument>") setType viewTree.tpe.paramTypes.head))
195+
valappliedTree=ApplyImplicitView(viewTree,List(Ident("<argument>") setType viewTree.tpe.paramTypes.head))
196196
valappliedTreeTyped:Tree= {
197197
valnewContext= context.makeImplicit(context.ambiguousErrors)
198198
newContext.macrosEnabled=false

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp