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:
@@ -289,9 +289,12 @@ public class DescriptorUtils {
|
||||
@NotNull
|
||||
public static Visibility getDefaultConstructorVisibility(@NotNull ClassDescriptor classDescriptor) {
|
||||
ClassKind classKind = classDescriptor.getKind();
|
||||
if (classKind == ClassKind.ENUM_CLASS || classKind.isSingleton() || isAnonymousObject(classDescriptor)) {
|
||||
if (classKind == ClassKind.ENUM_CLASS || classKind.isSingleton()) {
|
||||
return Visibilities.PRIVATE;
|
||||
}
|
||||
if (isAnonymousObject(classDescriptor)) {
|
||||
return Visibilities.INTERNAL;
|
||||
}
|
||||
assert classKind == ClassKind.CLASS || classKind == ClassKind.TRAIT || classKind == ClassKind.ANNOTATION_CLASS;
|
||||
return Visibilities.PUBLIC;
|
||||
}
|
||||
|
||||
@@ -70,16 +70,16 @@ public fun ImportPath.isImported(alreadyImported: ImportPath): Boolean {
|
||||
|
||||
public fun ImportPath.isImported(imports: Iterable<ImportPath>): Boolean = imports.any { isImported(it) }
|
||||
|
||||
// Check that it is javaName(\.javaName)* or an empty string
|
||||
private enum class State {
|
||||
BEGINNING
|
||||
MIDDLE
|
||||
AFTER_DOT
|
||||
}
|
||||
|
||||
public fun isValidJavaFqName(qualifiedName: String?): Boolean {
|
||||
if (qualifiedName == null) return false
|
||||
|
||||
// Check that it is javaName(\.javaName)* or an empty string
|
||||
enum class State {
|
||||
BEGINNING
|
||||
MIDDLE
|
||||
AFTER_DOT
|
||||
}
|
||||
|
||||
var state = State.BEGINNING
|
||||
|
||||
for (c in qualifiedName) {
|
||||
|
||||
Reference in New Issue
Block a user