JS frontend: added diagnostic about secondary constructors not supported yet.

This commit is contained in:
Zalim Bashorov
2015-03-20 12:28:01 +03:00
parent 9c88f9e744
commit d569ea5974
6 changed files with 54 additions and 0 deletions
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A {
<!SECONDARY_CONSTRUCTOR!>constructor()<!> {}
}
class B {
<!SECONDARY_CONSTRUCTOR!>constructor()<!> {}
<!SECONDARY_CONSTRUCTOR!>constructor(a: Int)<!> {}
}
class C(a: Int) {
<!SECONDARY_CONSTRUCTOR!>constructor()<!> : this(1) {}
<!SECONDARY_CONSTRUCTOR!>constructor(a: String)<!> : this(2) {}
}
@@ -0,0 +1,25 @@
package
internal final class A {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class B {
public constructor B()
public constructor B(/*0*/ a: kotlin.Int)
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class C {
public constructor C()
public constructor C(/*0*/ a: kotlin.Int)
public constructor C(/*0*/ a: kotlin.String)
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -572,5 +572,11 @@ public class JetDiagnosticsTestWithJsStdLibGenerated extends AbstractJetDiagnost
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/unsupportedFeatures/nestedInnerClassifier.kt");
doTest(fileName);
}
@TestMetadata("secondaryConstructor.kt")
public void testSecondaryConstructor() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/unsupportedFeatures/secondaryConstructor.kt");
doTest(fileName);
}
}
}
@@ -37,6 +37,7 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by Delegates.lazy {
put(ErrorsJs.NOT_SUPPORTED, "Cannot translate (not supported yet): ''{0}''", RenderFirstLineOfElementText)
put(ErrorsJs.REFERENCE_TO_BUILTIN_MEMBERS_NOT_SUPPORTED, "Callable references for builtin members are not supported yet: ''{0}''", RenderFirstLineOfElementText)
put(ErrorsJs.NON_TOPLEVEL_CLASS_DECLARATION, "Non-toplevel {0} declarations not supported yet", Renderers.STRING)
put(ErrorsJs.SECONDARY_CONSTRUCTOR, "Secondary constructors not supported yet")
this
@@ -43,6 +43,7 @@ public interface ErrorsJs {
DiagnosticFactory1<JetElement, JetElement> NOT_SUPPORTED = DiagnosticFactory1.create(ERROR, DEFAULT);
DiagnosticFactory1<JetElement, JetElement> REFERENCE_TO_BUILTIN_MEMBERS_NOT_SUPPORTED = DiagnosticFactory1.create(ERROR, DEFAULT);
DiagnosticFactory1<JetNamedDeclaration, String> NON_TOPLEVEL_CLASS_DECLARATION = DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
DiagnosticFactory0<JetNamedDeclaration> SECONDARY_CONSTRUCTOR = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
@SuppressWarnings("UnusedDeclaration")
Object _initializer = new Object() {
@@ -34,6 +34,12 @@ class ClassDeclarationChecker : DeclarationChecker {
if (declaration !is JetClassOrObject || declaration is JetObjectDeclaration || declaration is JetEnumEntry) return
if (declaration is JetClass) {
declaration.getSecondaryConstructors().forEach {
diagnosticHolder.report(ErrorsJs.SECONDARY_CONSTRUCTOR.on(it))
}
}
// hack to avoid to get diagnostics when compile kotlin builtins
val fqNameUnsafe = DescriptorUtils.getFqName(descriptor)
if (fqNameUnsafe.asString().startsWith("kotlin.")) return