Add diagnostic on calling inner classes constructors without receiver

Otherwise there will be just an unresolved reference that doesn't give
any useful information

 #KT-8959 Fixed
This commit is contained in:
Denis Zharkov
2017-02-28 15:28:20 +03:00
parent 1e0ae04aba
commit a7fc32c8da
17 changed files with 133 additions and 37 deletions
@@ -1,15 +1,15 @@
class Outer1 {
class Nested
class C1 { val b = Nested() }
class C2(val b: Any = Nested())
inner class C3 { val b = Nested() }
inner class C4(val b: Any = Nested())
inner class Inner
class C5 { val b = <!UNRESOLVED_REFERENCE!>Inner<!>() }
class C6(val b: Any = <!UNRESOLVED_REFERENCE!>Inner<!>())
class C5 { val b = <!RESOLUTION_TO_CLASSIFIER!>Inner<!>() }
class C6(val b: Any = <!RESOLUTION_TO_CLASSIFIER!>Inner<!>())
inner class C7 { val b = Inner() }
inner class C8(val b: Any = Inner())
}
@@ -18,15 +18,15 @@ class Outer1 {
class Outer2 {
class Nested {
fun foo() = Outer2()
fun bar() = <!UNRESOLVED_REFERENCE!>Inner<!>()
fun bar() = <!RESOLUTION_TO_CLASSIFIER!>Inner<!>()
}
inner class Inner {
fun foo() = Outer2()
fun bar() = Nested()
}
fun foo() {
Nested()
Inner()
}
}
}
@@ -0,0 +1,36 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// SKIP_TXT
// FILE: Outer.kt
package abc
class Outer {
inner class Inner() {
constructor(x: Int) : this() {}
}
companion object {
fun baz() {
<!RESOLUTION_TO_CLASSIFIER!>Inner<!>()
<!RESOLUTION_TO_CLASSIFIER!>Inner<!>(1)
}
}
}
fun foo() {
Outer.<!RESOLUTION_TO_CLASSIFIER!>Inner<!>()
Outer.<!RESOLUTION_TO_CLASSIFIER!>Inner<!>(1)
}
// FILE: imported.kt
import abc.Outer
import abc.Outer.Inner
fun bar() {
<!RESOLUTION_TO_CLASSIFIER!>Inner<!>()
<!RESOLUTION_TO_CLASSIFIER!>Inner<!>(1)
with(Outer()) {
Inner()
Inner(1)
}
}
@@ -0,0 +1,43 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// SKIP_TXT
// FILE: Outer.kt
package abc
class Outer {
inner class Inner() {
constructor(x: Int) : this() {}
}
companion object {
fun Inner(x: String) {}
fun baz() {
// Diagnostic here could be better (why can't I call the constructor above?)
Inner(<!NO_VALUE_FOR_PARAMETER!>)<!>
Inner(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>)
Inner("")
}
}
}
fun foo() {
Outer.Inner(<!NO_VALUE_FOR_PARAMETER!>)<!>
Outer.Inner(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>)
Outer.Inner("")
}
// FILE: imported.kt
import abc.Outer
import abc.Outer.Inner
import abc.Outer.Companion.Inner
fun bar() {
Inner(<!NO_VALUE_FOR_PARAMETER!>)<!>
Inner(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>)
Inner("")
with(Outer()) {
Inner()
Inner(1)
Inner("")
}
}
@@ -10,7 +10,7 @@ class Test {
}
fun more(): InnerClass {
val b = <!UNRESOLVED_REFERENCE!>InnerClass<!>()
val b = <!RESOLUTION_TO_CLASSIFIER!>InnerClass<!>()
val <!UNUSED_VARIABLE!>testVal<!> = <!UNRESOLVED_REFERENCE!>inClass<!>
<!UNRESOLVED_REFERENCE!>foo<!>()
@@ -23,4 +23,4 @@ class Test {
fun foo() {}
open inner class InnerClass
}
}
@@ -10,7 +10,7 @@ class Test {
}
fun more(): InnerClass {
val b = <!UNRESOLVED_REFERENCE!>InnerClass<!>()
val b = <!RESOLUTION_TO_CLASSIFIER!>InnerClass<!>()
val <!UNUSED_VARIABLE!>testVal<!> = <!UNRESOLVED_REFERENCE!>inClass<!>
<!UNRESOLVED_REFERENCE!>foo<!>()
@@ -24,4 +24,4 @@ class Test {
}
open inner class InnerClass
}
}
@@ -2,7 +2,7 @@ class Outer {
class Nested {
class NestedNested
}
inner class Inner {
inner class InnerInner
}
@@ -11,7 +11,7 @@ class Outer {
fun f1() = Outer()
fun f2() = Outer.Nested()
fun f3() = Outer.Nested.NestedNested()
fun f4() = Outer.<!UNRESOLVED_REFERENCE!>Inner<!>()
fun f5() = Outer.Inner.<!UNRESOLVED_REFERENCE!>InnerInner<!>()
fun f4() = Outer.<!RESOLUTION_TO_CLASSIFIER!>Inner<!>()
fun f5() = Outer.Inner.<!RESOLUTION_TO_CLASSIFIER!>InnerInner<!>()
fun f6() = Outer().Inner()
fun f7() = Outer().Inner().InnerInner()
fun f7() = Outer().Inner().InnerInner()