Drop traits with required classes

#KT-4771 Rejected
This commit is contained in:
Alexander Udalov
2015-06-16 23:40:25 +03:00
parent dc909ba1d4
commit 1a3209e1dc
63 changed files with 49 additions and 1109 deletions
@@ -2,8 +2,6 @@ open class A {
open fun foo(): Any = "A"
}
interface B : A
open class C : A() {
override fun foo(): Int = 222
}
@@ -12,14 +10,13 @@ interface D {
fun foo(): Number
}
class E : B, C(), D
class E : C(), D
fun box(): String {
val e = E()
if (e.foo() != 222) return "Fail 1"
if ((e : D).foo() != 222) return "Fail 2"
if ((e : C).foo() != 222) return "Fail 3"
if ((e : B).foo() != 222) return "Fail 4"
if ((e : A).foo() != 222) return "Fail 5"
if ((e : A).foo() != 222) return "Fail 4"
return "OK"
}
@@ -1,17 +0,0 @@
abstract class A {
abstract fun foo(): Any
}
interface B {
fun foo(): String = "B"
}
interface C : A, B
class D : A(), C
fun box(): String {
val d = D()
val r = d.foo() + (d : C).foo() + (d : B).foo() + (d : A).foo()
return if (r == "BBBB") "OK" else "Fail: $r"
}
@@ -1,15 +0,0 @@
open class A {
open fun foo(): Any = "A"
}
interface B : A {
override fun foo(): String = "B"
}
class C : A(), B
fun box(): String {
val c = C()
val r = c.foo() + (c : B).foo() + (c : A).foo()
return if (r == "BBB") "OK" else "Fail: $r"
}
-18
View File
@@ -1,18 +0,0 @@
open class A<T> {
open fun foo(a: T): Int = 2
}
interface B<T> : A<T> {
override fun foo(a: T): Int = 1
}
class D : B<Int>, A<Int>() {
fun boo(): Int {
return super<B>.foo(1)
}
}
fun box(): String {
if (D().boo() != 1) return "Fail"
return "OK"
}
@@ -24,8 +24,8 @@ class LI : ListTag() {}
public fun ListTag.item(body: LI.() -> Unit): Unit {}
fun HtmlTag.a(contents: A.() -> Unit) {}
interface A : HtmlTag {
public var text: String
abstract class A : HtmlTag() {
public abstract var text: String
}
fun listOf(vararg strings: String): List<String> {
@@ -34,4 +34,4 @@ fun listOf(vararg strings: String): List<String> {
list.add(s)
}
return list
}
}
@@ -1,17 +0,0 @@
open class Base {
val pr : String = "OK"
}
interface Trait : Base {
fun f() : String {
return this.pr
}
}
class A : Trait, Base() {
}
fun box() : String {
return if (A().f() == A().pr) "OK" else "fail"
}
-21
View File
@@ -1,21 +0,0 @@
open class Base {
open fun sayHello(): String {
return "O"
}
}
interface Trait: Base {
override fun sayHello(): String {
return "K"
}
}
class Derived(): Base(), Trait {
override fun sayHello(): String {
return super<Base>.sayHello() + super<Trait>.sayHello()
}
}
fun box(): String {
return Derived().sayHello()
}
@@ -1,15 +0,0 @@
open class AL<T> {
fun get(index: Int) : T? = null
}
interface ALE<T> : AL<T> {
fun getOrValue(index: Int, value : T) : T = get(index) ?: value
}
class SmartArrayList() : ALE<String>, AL<String>() {
}
fun box() : String {
val c = SmartArrayList()
return if("239" == c.getOrValue(0, "239")) "OK" else "fail"
}
@@ -1,19 +0,0 @@
abstract class Base<T> {
abstract var s: T
}
interface Trait<T> : Base<T> {
var value : T
get() = s
set(value) { s = value }
}
class Derived : Trait<String>, Base<String>() {
override var s = "Fail"
}
fun box(): String {
val d = Derived()
d.value = "OK"
return d.value
}
@@ -1,15 +0,0 @@
open class MyClass(param : String) {
var propterty = param
}
interface MyTrait : MyClass
{
fun foo() = propterty
}
open class B(param : String) : MyTrait, MyClass(param)
{
override fun foo() = super<MyTrait>.foo()
}
fun box()= B("OK").foo()
@@ -1,15 +0,0 @@
open class Base
interface Derived : Base {
fun foo(): String {
return object {
fun bar() = baz(this@Derived)
}.bar()
}
}
class DerivedImpl : Derived, Base()
fun baz(b: Base) = "OK"
fun box() = DerivedImpl().foo()
@@ -1,9 +0,0 @@
interface Trait<T : Enum<T>> : Enum<T> {
val value : String get() = name()
}
enum class E : Trait<E> {
OK
}
fun box() = E.OK.value
@@ -1,17 +0,0 @@
open class Base {
open fun sayHello(): String{
return "fail"
}
}
interface Trait: Base {
override fun sayHello(): String {
return "OK"
}
}
class Derived(): Base(), Trait
fun box() : String {
return Derived().sayHello()
}
@@ -1,17 +0,0 @@
open class Base {
var s = "Fail"
}
interface Trait : Base {
var value : String
get() = s
set(value) { s = value }
}
class Derived : Trait, Base()
fun box(): String {
val d = Derived()
d.value = "OK"
return d.value
}
@@ -1,14 +0,0 @@
open class Base
interface Trait : Base {
private val value : String
get() = "OK"
override fun toString() = object {
fun foo() = value
}.foo()
}
class Derived : Trait, Base()
fun box() = "${Derived()}"
@@ -1,11 +0,0 @@
interface Trait : java.lang.Object {
fun foo(): String = "239 " + toString()
}
class Impl : Trait, java.lang.Object() {
override fun toString() = "Impl"
}
fun box(): String {
return if ("239 Impl" == Impl().foo()) "OK" else "Fail"
}
@@ -1,18 +0,0 @@
open class Base {
open fun foo() : String {
return "fail"
}
}
interface Derived : Base {
override fun foo() : String {
//super.foo()
return "OK"
}
}
class DerivedImpl : Derived, Base()
fun box(): String {
return DerivedImpl().foo()
}
@@ -1,22 +0,0 @@
open class Base {
open fun foo() { }
open fun foo2() { }
}
interface Derived : Base {
override fun foo() {
object {
fun bar() {
//super<Base>@Derived.foo2()
this@Derived.foo2()
}
}.bar()
}
}
class DerivedImpl : Derived, Base()
fun box(): String {
DerivedImpl().foo()
return "OK"
}
@@ -1,17 +0,0 @@
open class Foo() {
public fun k(): String = "K"
}
interface T: Foo {
public fun xyzzy(): String = o() + k()
public fun o(): String
}
class TImpl(): Foo(), T {
public override fun o(): String = "O"
}
fun box(): String {
return TImpl().xyzzy()
}