JS: do not use getBuiltInsModule to compute module name
The intention of this code was to use the name "kotlin" for the builtins module, in case we're using builtins loaded from the compiler class loader (whose module is created in `KotlinBuiltIns.createBuiltInsModule`). However, `getBuiltIns().getBuiltInsModule()` may refer not necessarily to the builtins module, but also to any valid module where the builtins are visible from, therefore its name would be computed incorrectly. Use the module name instead to determine if it's a synthetic builtins module created in `createBuiltInsModule`
This commit is contained in:
@@ -711,24 +711,13 @@ public final class StaticContext {
|
||||
if (currentModule == module) {
|
||||
return currentModuleAsImported;
|
||||
}
|
||||
String moduleName = suggestModuleName(module);
|
||||
String moduleName = JsDescriptorUtils.getModuleName(module);
|
||||
|
||||
if (UNKNOWN_EXTERNAL_MODULE_NAME.equals(moduleName)) return null;
|
||||
|
||||
return getImportedModule(moduleName, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String suggestModuleName(@NotNull ModuleDescriptor module) {
|
||||
if (module == module.getBuiltIns().getBuiltInsModule()) {
|
||||
return Namer.KOTLIN_LOWER_NAME;
|
||||
}
|
||||
else {
|
||||
String moduleName = module.getName().asString();
|
||||
return moduleName.substring(1, moduleName.length() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsImportedModule getImportedModule(@NotNull String baseName, @Nullable DeclarationDescriptor descriptor) {
|
||||
String plainName = descriptor != null && config.getModuleKind() == ModuleKind.UMD ? getPlainId(descriptor) : null;
|
||||
@@ -835,9 +824,7 @@ public final class StaticContext {
|
||||
|
||||
@Nullable
|
||||
public JsExpression exportModuleForInline(@NotNull ModuleDescriptor declaration) {
|
||||
if (getCurrentModule().getBuiltIns().getBuiltInsModule() == declaration) return null;
|
||||
|
||||
String moduleName = suggestModuleName(declaration);
|
||||
String moduleName = JsDescriptorUtils.getModuleName(declaration);
|
||||
if (moduleName.equals(Namer.KOTLIN_LOWER_NAME)) return null;
|
||||
|
||||
JsImportedModule importedModule = getJsImportedModule(declaration);
|
||||
|
||||
@@ -149,11 +149,16 @@ public final class JsDescriptorUtils {
|
||||
|
||||
@NotNull
|
||||
public static String getModuleName(@NotNull DeclarationDescriptor descriptor) {
|
||||
ModuleDescriptor moduleDescriptor = DescriptorUtils.getContainingModule(findRealInlineDeclaration(descriptor));
|
||||
if (DescriptorUtils.getContainingModule(descriptor) == moduleDescriptor.getBuiltIns().getBuiltInsModule()) {
|
||||
return getModuleName(DescriptorUtils.getContainingModule(findRealInlineDeclaration(descriptor)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getModuleName(@NotNull ModuleDescriptor module) {
|
||||
if (module.getName().equals(KotlinBuiltIns.BUILTINS_MODULE_NAME)) {
|
||||
return Namer.KOTLIN_LOWER_NAME;
|
||||
}
|
||||
String moduleName = moduleDescriptor.getName().asString();
|
||||
|
||||
String moduleName = module.getName().asString();
|
||||
return moduleName.substring(1, moduleName.length() - 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user