From 529040c83b7dc48ab320d16835fb7390c5722984 Mon Sep 17 00:00:00 2001 From: Paul Coral Date: Fri, 13 Jan 2023 15:37:08 +0100 Subject: [PATCH] Fix false positive for named args (and other) - Fix the non-miniphase traverser - Update test cases --- .../src/dotty/tools/dotc/transform/CheckUnused.scala | 7 +++++-- tests/neg-custom-args/fatal-warnings/i15503i.scala | 12 +++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index 29af47ce844e..d7039d8ae3e0 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -197,12 +197,15 @@ class CheckUnused extends MiniPhase: case t:tpd.ValDef => prepareForValDef(t) traverseChildren(tree)(using newCtx) + transformValDef(t) case t:tpd.DefDef => prepareForDefDef(t) traverseChildren(tree)(using newCtx) + transformDefDef(t) case t:tpd.TypeDef => prepareForTypeDef(t) traverseChildren(tree)(using newCtx) + transformTypeDef(t) case t: tpd.Bind => prepareForBind(t) traverseChildren(tree)(using newCtx) @@ -325,7 +328,7 @@ object CheckUnused: * The optional name will be used to target the right import * as the same element can be imported with different renaming */ - def registerUsed(sym: Symbol, name: Option[Name])(using Context): Unit = + def registerUsed(sym: Symbol, name: Option[Name])(using Context): Unit = if !isConstructorOfSynth(sym) && !doNotRegister(sym) then if sym.isConstructor && sym.exists then registerUsed(sym.owner, None) // constructor are "implicitly" imported with the class @@ -365,7 +368,7 @@ object CheckUnused: implicitParamInScope += memDef else explicitParamInScope += memDef - else if currScopeType.top == ScopeType.Local then + else if currScopeType.top == ScopeType.Local then localDefInScope += memDef else if currScopeType.top == ScopeType.Template && memDef.symbol.is(Private, butNot = SelfName) then privateDefInScope += memDef diff --git a/tests/neg-custom-args/fatal-warnings/i15503i.scala b/tests/neg-custom-args/fatal-warnings/i15503i.scala index 60a1ad4741fd..341f290b9afa 100644 --- a/tests/neg-custom-args/fatal-warnings/i15503i.scala +++ b/tests/neg-custom-args/fatal-warnings/i15503i.scala @@ -73,4 +73,14 @@ package foo.test.companionprivate: object A: private def b = c // OK - def c = List(1,2,3) // OK \ No newline at end of file + def c = List(1,2,3) // OK + +package foo.test.i16678: + def foo(func: Int => String, value: Int): String = func(value) // OK + + def run = + println(foo(number => number.toString, value = 5)) // OK + println(foo(number => "", value = 5)) // error + println(foo(func = number => "", value = 5)) // error + println(foo(func = number => number.toString, value = 5)) // OK + println(foo(func = _.toString, value = 5)) // OK \ No newline at end of file