KT-1033 Generate implementations produces wrong code

This commit is contained in:
Nikolay Krasko
2012-01-18 12:16:40 +04:00
parent e2782e0766
commit 2a3d1b2b45
10 changed files with 50 additions and 10 deletions
@@ -73,7 +73,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
this, this,
annotations, annotations,
false, false,
"&" + name, name,
Collections.<TypeParameterDescriptor>emptyList(), Collections.<TypeParameterDescriptor>emptyList(),
upperBounds); upperBounds);
} }
@@ -104,12 +104,15 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
if (!returnType.equals(stdlib.getTuple0Type())) { if (!returnType.equals(stdlib.getTuple0Type())) {
bodyBuilder.append(": ").append(returnType.toString()); bodyBuilder.append(": ").append(returnType.toString());
} }
bodyBuilder.append("{");
final String initializer = defaultInitializer(returnType, stdlib); final String initializer = defaultInitializer(returnType, stdlib);
if (initializer != null) { if (initializer != null) {
bodyBuilder.append("return " ).append(initializer); bodyBuilder.append(" = ").append(initializer);
} }
bodyBuilder.append("}"); else {
bodyBuilder.append("{").append("throw UnsupportedOperationException()").append("}");
}
return JetPsiFactory.createFunction(project, bodyBuilder.toString()); return JetPsiFactory.createFunction(project, bodyBuilder.toString());
} }
@@ -4,7 +4,5 @@ trait G<T> {
class GC() : G<Int> { class GC() : G<Int> {
override fun foo(t: Int): Int { override fun foo(t: Int): Int = 0
return 0
}
} }
@@ -2,7 +2,5 @@ import foo.Intf
class Impl(): Intf { class Impl(): Intf {
override fun getFooBar(): String? { override fun getFooBar(): String? = null
return null
}
} }
@@ -3,5 +3,6 @@ import foo.Intf
class Impl(): Intf { class Impl(): Intf {
override fun fooBar(i: Int, s: Array<String?>?, foo: Any?) { override fun fooBar(i: Int, s: Array<String?>?, foo: Any?) {
throw UnsupportedOperationException()
} }
} }
@@ -0,0 +1,7 @@
trait G<T> {
fun foo(t : T) : T
}
class GC<T>() : G<T> {
<caret>
}
@@ -0,0 +1,10 @@
trait G<T> {
fun foo(t : T) : T
}
class GC<T>() : G<T> {
override fun foo(t: T): T {
throw UnsupportedOperationException()
}
}
@@ -0,0 +1,7 @@
trait Some {
fun foo(some : Int?) : Int
}
class SomeOther : Some {
<caret>
}
@@ -0,0 +1,8 @@
trait Some {
fun foo(some : Int?) : Int
}
class SomeOther : Some {
override fun foo(some: Int?): Int = 0
}
@@ -46,6 +46,14 @@ public class OverrideImplementTest extends LightCodeInsightFixtureTestCase {
doFileTest(); doFileTest();
} }
public void testTraitGenericOverride() {
doFileTest();
}
public void testTraitNullableFunction() {
doFileTest();
}
private void doFileTest() { private void doFileTest() {
myFixture.configureByFile(getTestName(true) + ".kt"); myFixture.configureByFile(getTestName(true) + ".kt");
doImplement(); doImplement();