Skip to content

Commit 0e0caac

Browse files
committed
Patvars
Absolution of canonical names defn.LanguageFeatureMetaAnnot
1 parent 4379f96 commit 0e0caac

File tree

13 files changed

+329
-74
lines changed

13 files changed

+329
-74
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ object desugar {
4747
*/
4848
val UntupledParam: Property.Key[Unit] = Property.StickyKey()
4949

50+
/** An attachment key to indicate that a ValDef originated from a pattern.
51+
*/
52+
val PatternVar: Property.Key[Unit] = Property.StickyKey()
53+
54+
/** An attachment key for Trees originating in for-comprehension, such as tupling of assignments.
55+
*/
56+
val ForArtifact: Property.Key[Unit] = Property.StickyKey()
57+
5058
/** An attachment key to indicate that a ValDef is an evidence parameter
5159
* for a context bound.
5260
*/
@@ -1505,7 +1513,7 @@ object desugar {
15051513
val matchExpr =
15061514
if (tupleOptimizable) rhs
15071515
else
1508-
val caseDef = CaseDef(pat, EmptyTree, makeTuple(ids))
1516+
val caseDef = CaseDef(pat, EmptyTree, makeTuple(ids).withAttachment(ForArtifact, ()))
15091517
Match(makeSelector(rhs, MatchCheck.IrrefutablePatDef), caseDef :: Nil)
15101518
vars match {
15111519
case Nil if !mods.is(Lazy) =>
@@ -1535,6 +1543,7 @@ object desugar {
15351543
ValDef(named.name.asTermName, tpt, selector(n))
15361544
.withMods(mods)
15371545
.withSpan(named.span)
1546+
.withAttachment(PatternVar, ())
15381547
)
15391548
flatTree(firstDef :: restDefs)
15401549
}
@@ -1920,6 +1929,7 @@ object desugar {
19201929
val vdef = ValDef(named.name.asTermName, tpt, rhs)
19211930
.withMods(mods)
19221931
.withSpan(original.span.withPoint(named.span.start))
1932+
.withAttachment(PatternVar, ())
19231933
val mayNeedSetter = valDef(vdef)
19241934
mayNeedSetter
19251935
}
@@ -2165,7 +2175,7 @@ object desugar {
21652175
case _ => Modifiers()
21662176
makePatDef(valeq, mods, defpat, rhs)
21672177
}
2168-
val rhs1 = makeFor(nme.map, nme.flatMap, GenFrom(defpat0, gen.expr, gen.checkMode) :: Nil, Block(pdefs, makeTuple(id0 :: ids)))
2178+
val rhs1 = makeFor(nme.map, nme.flatMap, GenFrom(defpat0, gen.expr, gen.checkMode) :: Nil, Block(pdefs, makeTuple(id0 :: ids).withAttachment(ForArtifact, ())))
21692179
val allpats = gen.pat :: pats
21702180
val vfrom1 = GenFrom(makeTuple(allpats), rhs1, GenCheckMode.Ignore)
21712181
makeFor(mapName, flatMapName, vfrom1 :: rest1, body)

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ private sealed trait WarningSettings:
181181
ChoiceWithHelp("explicits", "Warn if an explicit parameter is unused"),
182182
ChoiceWithHelp("implicits", "Warn if an implicit parameter is unused"),
183183
ChoiceWithHelp("params", "Enable -Wunused:explicits,implicits"),
184+
ChoiceWithHelp("patvars","Warn if a variable bound in a pattern is unused"),
184185
ChoiceWithHelp("linted", "Enable -Wunused:imports,privates,locals,implicits"),
185186
ChoiceWithHelp(
186187
name = "strict-no-implicit-warn",
187188
description = "Same as -Wunused:import, only for imports of explicit named members.\n" +
188189
"NOTE : This overrides -Wunused:imports and NOT set by -Wunused:all"
189190
),
190-
// ChoiceWithHelp("patvars","Warn if a variable bound in a pattern is unused"),
191191
ChoiceWithHelp(
192192
name = "unsafe-warn-patvars",
193193
description = "(UNSAFE) Warn if a variable bound in a pattern is unused.\n" +
@@ -220,8 +220,8 @@ private sealed trait WarningSettings:
220220
def privates(using Context) =
221221
allOr("privates") || allOr("linted")
222222
def patvars(using Context) =
223-
isChoiceSet("unsafe-warn-patvars") // not with "all"
224-
// allOr("patvars") // todo : rename once fixed
223+
allOr("patvars")
224+
//isChoiceSet("unsafe-warn-patvars") // not with "all"
225225
def linted(using Context) =
226226
allOr("linted")
227227
def strictNoImplicitWarn(using Context) =

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,7 @@ class Definitions {
10631063
@tu lazy val UntrackedCapturesAnnot: ClassSymbol = requiredClass("scala.caps.untrackedCaptures")
10641064
@tu lazy val UseAnnot: ClassSymbol = requiredClass("scala.caps.use")
10651065
@tu lazy val VolatileAnnot: ClassSymbol = requiredClass("scala.volatile")
1066+
@tu lazy val LanguageFeatureMetaAnnot: ClassSymbol = requiredClass("scala.annotation.meta.languageFeature")
10661067
@tu lazy val BeanGetterMetaAnnot: ClassSymbol = requiredClass("scala.annotation.meta.beanGetter")
10671068
@tu lazy val BeanSetterMetaAnnot: ClassSymbol = requiredClass("scala.annotation.meta.beanSetter")
10681069
@tu lazy val FieldMetaAnnot: ClassSymbol = requiredClass("scala.annotation.meta.field")

0 commit comments

Comments
 (0)