Prohibit local objects and enum classes
#KT-5402 Fixed
#KT-4838 Fixed
Resolve type of object inside local object as special, not supertype('Any').
Changed visibility of constructor of anonymous object to 'internal' to be able to resolve the following:
fun box(): String {
var foo = object {
val bar = object {
val baz = "ok"
}
}
return foo.bar.baz
}
The containing declaration of property initializers is constructor, so 'baz' was invisible inside private constructor.
This commit is contained in:
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.OverrideResolver;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -37,6 +38,7 @@ import java.util.*;
|
||||
|
||||
import static com.google.dart.compiler.backend.js.ast.JsBinaryOperator.*;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getFqName;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isAnonymousObject;
|
||||
import static org.jetbrains.k2js.translate.context.Namer.getKotlinBackingFieldName;
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getCallableDescriptorForOperationExpression;
|
||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.*;
|
||||
@@ -418,9 +420,11 @@ public final class TranslationUtils {
|
||||
public static String getSuggestedNameForInnerDeclaration(TranslationContext context, DeclarationDescriptor descriptor) {
|
||||
String suggestedName = "";
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
//noinspection ConstantConditions
|
||||
if (containingDeclaration != null &&
|
||||
!(containingDeclaration instanceof ClassOrPackageFragmentDescriptor) &&
|
||||
!(containingDeclaration instanceof AnonymousFunctionDescriptor)) {
|
||||
!(containingDeclaration instanceof AnonymousFunctionDescriptor) &&
|
||||
!(containingDeclaration instanceof ConstructorDescriptor && isAnonymousObject(containingDeclaration.getContainingDeclaration()))) {
|
||||
suggestedName = context.getNameForDescriptor(containingDeclaration).getIdent();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package foo
|
||||
fun box(): String {
|
||||
var boo = "OK"
|
||||
var foo = object {
|
||||
object bar {
|
||||
val bar = object {
|
||||
val baz = boo
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,10 @@ package foo
|
||||
|
||||
class A() {
|
||||
fun f(): Boolean {
|
||||
object t {
|
||||
val c = true;
|
||||
}
|
||||
val z = object {
|
||||
val c = true
|
||||
}
|
||||
return t.c && z.c
|
||||
return z.c
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ class Foo {
|
||||
fun bar(param: String): String {
|
||||
val local = "world!"
|
||||
var a = object {
|
||||
object b {
|
||||
val b = object {
|
||||
val bar = param + local
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user