Don't mark parameters of get/set/propertyDelegated functions as unused.

#KT-5974 fixed
This commit is contained in:
Evgeny Gerashchenko
2015-02-18 15:31:55 +03:00
parent dbe9a70fbd
commit 056daeaadb
16 changed files with 52 additions and 29 deletions
@@ -649,10 +649,15 @@ public class JetFlowInformationProvider {
DeclarationDescriptor descriptor = trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, owner);
assert descriptor instanceof FunctionDescriptor : owner.getText();
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
if (!isMain && !functionDescriptor.getModality().isOverridable()
&& functionDescriptor.getOverriddenDescriptors().isEmpty()) {
report(Errors.UNUSED_PARAMETER.on((JetParameter) element, variableDescriptor), ctxt);
String functionName = functionDescriptor.getName().asString();
if (isMain
|| functionDescriptor.getModality().isOverridable()
|| !functionDescriptor.getOverriddenDescriptors().isEmpty()
|| "get".equals(functionName) || "set".equals(functionName) || "propertyDelegated".equals(functionName)
) {
return;
}
report(Errors.UNUSED_PARAMETER.on((JetParameter) element, variableDescriptor), ctxt);
} else if (owner instanceof JetClass) {
if (!((JetParameter) element).hasValOrVarNode() && !((JetClass) owner).isAnnotation()) {
report(Errors.UNUSED_PARAMETER.on((JetParameter) element, variableDescriptor), ctxt);
@@ -12,4 +12,17 @@ class C(a: Int, b: Int, c: Int, d: Int, <!UNUSED_PARAMETER!>e<!>: Int = d, val f
fun f(a: Int, b: Int, <!UNUSED_PARAMETER!>c<!>: Int = b) {
a + a
}
}
fun Any.get(thisRef: Any?, prop: PropertyMetadata): String = ":)"
fun Any.set(thisRef: Any?, prop: PropertyMetadata, value: String) {
}
fun Any.propertyDelegated(prop: PropertyMetadata) {
}
fun get(p: Any) {
}
fun set(p: Any) {
}
@@ -1,6 +1,11 @@
package
internal fun f(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int, /*2*/ c: kotlin.Int = ...): kotlin.Unit
internal fun get(/*0*/ p: kotlin.Any): kotlin.Unit
internal fun set(/*0*/ p: kotlin.Any): kotlin.Unit
internal fun kotlin.Any.get(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.PropertyMetadata): kotlin.String
internal fun kotlin.Any.propertyDelegated(/*0*/ prop: kotlin.PropertyMetadata): kotlin.Unit
internal fun kotlin.Any.set(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.PropertyMetadata, /*2*/ value: kotlin.String): kotlin.Unit
internal final class C {
public constructor C(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int, /*2*/ c: kotlin.Int, /*3*/ d: kotlin.Int, /*4*/ e: kotlin.Int = ..., /*5*/ f: kotlin.String)
@@ -19,8 +19,8 @@ fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) {
//Arrays copy example
class Array<T>(val length : Int, val t : T) {
fun get(<!UNUSED_PARAMETER!>index<!> : Int) : T { return t }
fun set(<!UNUSED_PARAMETER!>index<!> : Int, <!UNUSED_PARAMETER!>value<!> : T) { /* ... */ }
fun get(index : Int) : T { return t }
fun set(index : Int, value : T) { /* ... */ }
}
fun copy1(<!UNUSED_PARAMETER!>from<!> : Array<Any>, <!UNUSED_PARAMETER!>to<!> : Array<Any>) {}
@@ -1,5 +1,5 @@
class Del {
fun get(<!UNUSED_PARAMETER!>_this<!>: Any?, <!UNUSED_PARAMETER!>p<!>: PropertyMetadata): Int = 0
fun get(_this: Any?, p: PropertyMetadata): Int = 0
}
fun df(del: Del): Del = del
@@ -9,11 +9,11 @@ fun getMyProperty1<A, B>() = MyProperty1<A, B>()
class MyProperty1<T, R> {
public fun get(<!UNUSED_PARAMETER!>thisRef<!>: R, <!UNUSED_PARAMETER!>desc<!>: PropertyMetadata): T {
public fun get(thisRef: R, desc: PropertyMetadata): T {
throw Exception()
}
public fun set(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>j<!>: Int, <!UNUSED_PARAMETER!>k<!>: Int) {
public fun set(i: Int, j: Int, k: Int) {
println("set")
}
}
@@ -29,11 +29,11 @@ fun getMyProperty2<A, B>() = MyProperty2<A, B>()
class MyProperty2<T, R> {
public fun get(<!UNUSED_PARAMETER!>thisRef<!>: R, <!UNUSED_PARAMETER!>desc<!>: PropertyMetadata): T {
public fun get(thisRef: R, desc: PropertyMetadata): T {
throw Exception()
}
public fun set(<!UNUSED_PARAMETER!>i<!>: Int) {
public fun set(i: Int) {
println("set")
}
}
@@ -5,11 +5,11 @@ class A {
var aTopLevel: Int by Delegate()
class Delegate {
fun get(<!UNUSED_PARAMETER!>t<!>: Nothing?, p: PropertyMetadata): Int {
fun get(t: Nothing?, p: PropertyMetadata): Int {
p.equals(null) // to avoid UNUSED_PARAMETER warning
return 1
}
fun set(<!UNUSED_PARAMETER!>t<!>: Nothing?, p: PropertyMetadata, a: Int) {
fun set(t: Nothing?, p: PropertyMetadata, a: Int) {
p.equals(a) // to avoid UNUSED_PARAMETER warning
}
}
@@ -5,11 +5,11 @@ class A {
var aTopLevel: Int by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>Delegate()<!>
class Delegate {
fun get(<!UNUSED_PARAMETER!>t<!>: Nothing, p: PropertyMetadata): Int {
fun get(t: Nothing, p: PropertyMetadata): Int {
p.equals(null) // to avoid UNUSED_PARAMETER warning
return 1
}
fun set(<!UNUSED_PARAMETER!>t<!>: Nothing, p: PropertyMetadata, a: Int) {
fun set(t: Nothing, p: PropertyMetadata, a: Int) {
p.equals(a) // to avoid UNUSED_PARAMETER warning
}
}
@@ -1,4 +1,4 @@
fun set(<!UNUSED_PARAMETER!>key<!> : String, <!UNUSED_PARAMETER!>value<!> : String) {
fun set(key : String, value : String) {
val a : String? = ""
when (a) {
"" -> <!DEBUG_INFO_SMARTCAST!>a<!>.get(0)
@@ -35,13 +35,13 @@ fun main(args: Array<String>) {
}
class MyArray() {
fun get(<!UNUSED_PARAMETER!>i<!>: Int): Int = 1
fun set(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>value<!>: Int): Int = 1
fun get(i: Int): Int = 1
fun set(i: Int, value: Int): Int = 1
}
class MyArray1() {
fun get(<!UNUSED_PARAMETER!>i<!>: Int): Int = 1
fun set(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>value<!>: Int) {}
fun get(i: Int): Int = 1
fun set(i: Int, value: Int) {}
}
class MyNumber() {
@@ -7,4 +7,4 @@ fun test() {
attributes["href"] = "1" // inference fails, but it shouldn't
}
fun <K, V> MutableMap<K, V>.set(<!UNUSED_PARAMETER!>key<!> : K, <!UNUSED_PARAMETER!>value<!> : V) {}//= this.put(key, value)
fun <K, V> MutableMap<K, V>.set(key : K, value : V) {}//= this.put(key, value)
@@ -5,4 +5,4 @@ fun test() {
attributes["href"] = "1" // inference fails, but it shouldn't
}
fun <K, V> Map<K, V>.set(<!UNUSED_PARAMETER!>key<!> : K, <!UNUSED_PARAMETER!>value<!> : V) {}//= this.put(key, value)
fun <K, V> Map<K, V>.set(key : K, value : V) {}//= this.put(key, value)
@@ -3,8 +3,8 @@ trait Out<out T>
trait Inv<T>
class Delegate<T> {
fun get(<!UNUSED_PARAMETER(t)!>t<!>: Any, <!UNUSED_PARAMETER(p)!>p<!>: PropertyMetadata): T = null!!
fun set(<!UNUSED_PARAMETER(t)!>t<!>: Any, <!UNUSED_PARAMETER(p)!>p<!>: PropertyMetadata, <!UNUSED_PARAMETER(value)!>value<!>: T) {}
fun get(t: Any, p: PropertyMetadata): T = null!!
fun set(t: Any, p: PropertyMetadata, value: T) {}
}
fun <T> getT(): T = null!!
@@ -3,8 +3,8 @@ trait Out<out T>
trait Inv<T>
class Delegate<T> {
fun get(<!UNUSED_PARAMETER(t)!>t<!>: Any, <!UNUSED_PARAMETER(p)!>p<!>: PropertyMetadata): T = null!!
fun set(<!UNUSED_PARAMETER(t)!>t<!>: Any, <!UNUSED_PARAMETER(p)!>p<!>: PropertyMetadata, <!UNUSED_PARAMETER(varue)!>varue<!>: T) {}
fun get(t: Any, p: PropertyMetadata): T = null!!
fun set(t: Any, p: PropertyMetadata, varue: T) {}
}
fun <T> getT(): T = null!!
+2 -2
View File
@@ -19,8 +19,8 @@ fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) {
//Arrays copy example
class Array<T>(val length : Int, val t : T) {
fun get(<warning>index</warning> : Int) : T { return t }
fun set(<warning>index</warning> : Int, <warning>value</warning> : T) { /* ... */ }
fun get(index : Int) : T { return t }
fun set(index : Int, value : T) { /* ... */ }
}
fun copy1(<warning>from</warning> : Array<Any>, <warning>to</warning> : Array<Any>) {}
+1 -1
View File
@@ -1,4 +1,4 @@
fun set(<warning>key</warning> : String, <warning>value</warning> : String) {
fun set(key : String, value : String) {
val a : String? = ""
when (a) {
"" -> a.get(0)