Skip to content

Commit 1523f3d

Browse files
committed
Fix extension methods with unused parameters
1 parent f4a0ab9 commit 1523f3d

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
196196
case tp: MethodType =>
197197
def valueParam(name: TermName, info: Type): TermSymbol = {
198198
val maybeImplicit = if (tp.isImplicitMethod) Implicit else EmptyFlags
199-
ctx.newSymbol(sym, name, TermParam | maybeImplicit, info)
199+
val maybeUnused = if (tp.isUnusedMethod) Unused else EmptyFlags
200+
ctx.newSymbol(sym, name, TermParam | maybeImplicit | maybeUnused, info)
200201
}
201202
val params = (tp.paramNames, tp.paramInfos).zipped.map(valueParam)
202203
val (paramss, rtp) = valueParamss(tp.instantiate(params map (_.termRef)))

compiler/src/dotty/tools/dotc/transform/FullParameterization.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,17 @@ trait FullParameterization {
229229
.appliedToTypes(allInstanceTypeParams(originalDef, abstractOverClass).map(_.typeRef))
230230
.appliedTo(This(originalDef.symbol.enclosingClass.asClass))
231231

232+
def refOrDefault(tree: Tree): Tree = // use deafult values for
233+
if (tree.symbol is Flags.Unused) tpd.defaultValue(tree.tpe) else ref(tree.symbol)
234+
232235
(if (!liftThisType)
233-
fun.appliedToArgss(originalDef.vparamss.nestedMap(vparam => ref(vparam.symbol)))
236+
fun.appliedToArgss(originalDef.vparamss.nestedMap(vparam => refOrDefault(vparam)))
234237
else {
235238
// this type could have changed on forwarding. Need to insert a cast.
236239
val args = (originalDef.vparamss, fun.tpe.paramInfoss).zipped.map((vparams, paramTypes) =>
237240
(vparams, paramTypes).zipped.map((vparam, paramType) => {
238241
assert(vparam.tpe <:< paramType.widen) // type should still conform to widened type
239-
ref(vparam.symbol).ensureConforms(paramType)
242+
refOrDefault(vparam).ensureConforms(paramType)
240243
})
241244
)
242245
fun.appliedToArgss(args)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class IntDeco(x: Int) extends AnyVal {
2+
def foo(unused y: Int) = x
3+
}

0 commit comments

Comments
 (0)