object declarations need trait methods to be generated too (KT-2399)
This commit is contained in:
@@ -745,7 +745,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void generateTraitMethods(ExpressionCodegen codegen) {
|
private void generateTraitMethods(ExpressionCodegen codegen) {
|
||||||
if (!(myClass instanceof JetClass) || ((JetClass)myClass).isTrait() || ((JetClass)myClass).hasModifier(JetTokens.ABSTRACT_KEYWORD))
|
if (myClass instanceof JetClass && (((JetClass)myClass).isTrait() || ((JetClass)myClass).hasModifier(JetTokens.ABSTRACT_KEYWORD)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (Pair<CallableMemberDescriptor, CallableMemberDescriptor> needDelegates : getTraitImplementations(descriptor)) {
|
for (Pair<CallableMemberDescriptor, CallableMemberDescriptor> needDelegates : getTraitImplementations(descriptor)) {
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import java.util.Collection
|
||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
|
class JsonObject {
|
||||||
|
}
|
||||||
|
|
||||||
|
class JsonArray {
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProjectInfo {
|
||||||
|
public fun toString(): String = "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
public trait Parser<in IN: Any, out OUT: Any> {
|
||||||
|
public fun parse(source: IN): OUT
|
||||||
|
}
|
||||||
|
|
||||||
|
public trait MultiParser<in IN: Any, out OUT: Any> {
|
||||||
|
public fun parse(source: IN): Collection<OUT>
|
||||||
|
}
|
||||||
|
|
||||||
|
public trait JsonParser<T: Any>: Parser<JsonObject, T>, MultiParser<JsonArray, T> {
|
||||||
|
public override fun parse(source: JsonArray): Collection<T> {
|
||||||
|
return ArrayList<T>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class ProjectInfoJsonParser(): JsonParser<ProjectInfo> {
|
||||||
|
public override fun parse(source: JsonObject): ProjectInfo {
|
||||||
|
return ProjectInfo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProjectApiContext {
|
||||||
|
public val projectInfoJsonParser: ProjectInfoJsonParser = object : ProjectInfoJsonParser(){
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val context = ProjectApiContext()
|
||||||
|
val array = context.projectInfoJsonParser.parse(JsonArray())
|
||||||
|
return if (array != null) "OK" else "fail"
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ package org.jetbrains.jet.codegen;
|
|||||||
|
|
||||||
import org.jetbrains.jet.ConfigurationKind;
|
import org.jetbrains.jet.ConfigurationKind;
|
||||||
|
|
||||||
public class TraitsTest extends CodegenTestCase {
|
public class TraitsTest extends CodegenTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
@@ -31,29 +31,33 @@ public class TraitsTest extends CodegenTestCase {
|
|||||||
return "traits";
|
return "traits";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimple () throws Exception {
|
public void testSimple () {
|
||||||
blackBoxFile("traits/simple.jet");
|
blackBoxFile("traits/simple.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithRequired () throws Exception {
|
public void testWithRequired () {
|
||||||
blackBoxFile("traits/withRequired.jet");
|
blackBoxFile("traits/withRequired.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultiple () throws Exception {
|
public void testMultiple () {
|
||||||
blackBoxFile("traits/multiple.jet");
|
blackBoxFile("traits/multiple.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStdlib () throws Exception {
|
public void testStdlib () {
|
||||||
blackBoxFile("traits/stdlib.jet");
|
blackBoxFile("traits/stdlib.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInheritedFun() throws Exception {
|
public void testInheritedFun() {
|
||||||
blackBoxFile("traits/inheritedFun.jet");
|
blackBoxFile("traits/inheritedFun.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInheritedVar() throws Exception {
|
public void testInheritedVar() {
|
||||||
blackBoxFile("traits/inheritedVar.jet");
|
blackBoxFile("traits/inheritedVar.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testKt2399() {
|
||||||
|
blackBoxFile("regressions/kt2399.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user