Compare commits

...

76 Commits

Author SHA1 Message Date
Simon Ogorodnik
26da9976d2 Update changeling for 1.2-Beta 2017-09-29 14:42:52 +03:00
Dmitry Jemerov
ae135d979f Mark multiplatform projects as experimental in the UI 2017-09-27 17:29:01 +02:00
Nikolay Krasko
2950495c4a Execute action without writeActionPriority in tests
(cherry picked from commit ab6bc43)
2017-09-27 16:19:38 +03:00
Ilya Gorbunov
8cdde268c6 Fixup "Refactor: use the same arraybuffer to compute double hashcode": switch indices 2017-09-25 22:06:10 +03:00
Denis Zharkov
00146b383c Use Jsr305State.DEFAULT instead of IGNORE as a default value 2017-09-25 20:06:59 +03:00
Denis Zharkov
cc244f717e Fix loading additional compiler arguments from facets for libraries 2017-09-25 20:06:50 +03:00
Dmitry Jemerov
27c01598e8 Don't show "Run tests" gutter icon when there's nothing to run
#KT-20338 Fixed
2017-09-25 12:04:28 +02:00
Mikhail Glukhikh
6a11584cde Expect/actual: add inspection for Suppress("DIAGNOSTIC") migration
So #KT-20328 Fixed
2017-09-22 20:23:02 +03:00
Mikhail Glukhikh
1a9fc4fdc8 Fix a pair of multi-platform messages #KT-20327 Fixed 2017-09-22 20:22:49 +03:00
Sergey Igushkin
610a303bfa Revert "Fix agp25 source set Kotlin classes not included in kotlin-gradle-plugin"
This reverts commit 25ca079
2017-09-22 17:57:33 +03:00
Sergey Igushkin
f831d88259 Fix agp25 source set Kotlin classes not included in kotlin-gradle-plugin
(cherry picked from commit 25ca079)
2017-09-22 17:41:42 +03:00
Dmitry Jemerov
078acbb1a6 Fix exception in KotlinExpandNodeProjectViewProvider.modify 2017-09-21 15:22:28 +02:00
Stanislav Erokhin
1333442a96 Support expected type from explicit cast
This commit support the following case.
Suppose we have such declaration:
  fun <T> foo(): T { ... }

Then in code we want to use it like this: `foo() as String`.
But in LV <= 1.1 we have type inference error: "Not enough
information for type parameter `T`". This error happened because we
do not use type from cast as expected type for call.

In this commit we fix this problem and use this type as expected type
in following cases:
 - our function has only one type parameter (this can be relaxed later)
 - function parameter types and extension receiver type not contains `T`

Also this fix problem with `findViewById`.
Already signature was: `fun findViewById(...): View`
and was used like: `findViewById() as MyView`.
New signature is `fun <T : View> findViewById(...): T`
and old usage was broken because of problem described above
2017-09-21 16:06:19 +03:00
Mikhail Glukhikh
1e85dc3e12 Add DEPRECATED_MODIFIER to cleanup diagnostic list 2017-09-21 15:57:25 +03:00
Anton Bannykh
6c77a19794 JS: temporarily remove @Before @After annotations
(cherry picked from commit 0976a78)
2017-09-21 14:53:41 +03:00
Anton Bannykh
a8a0666ea5 JS: Support isInitialized intrisic for lateinit properties 2017-09-20 14:45:38 +03:00
Sergey Igushkin
103b41e90d Fix javaOutputDir changed to the JAR, which was breaking unit tests
internal visibility, because they did not get the JAR into classpath

Issue #KT-20212 Fixed

(cherry picked from commit 41b13d2)
2017-09-19 15:38:04 +03:00
Alexey Sedunov
50960a61d0 Misc: Fix multiplatform test configuration
(cherry picked from commit 04a4bef)
2017-09-18 20:52:16 +03:00
Dmitry Jemerov
75bd6264f5 Correctly detect multiplatform modules in run code
LanguageVersionSettings doesn't mean that the module is actually
multiplatform; it only means that it _could_ be one. Use
platform and information from facet instead.

Also fix detection of common stdlib version and add tests for common
run config.
2017-09-18 19:47:38 +02:00
Dmitry Jemerov
ad1663ec73 Add missing dependencies 2017-09-18 19:47:22 +02:00
Alexander Udalov
6d3a1bb51b Support -Werror CLI argument to treat warnings as errors
The option is named "warningsAsErrors" in the Gradle plugin

 #KT-10563 Fixed
2017-09-18 18:01:06 +03:00
Alexander Udalov
040de90d14 Add test on compiling against kotlin.reflect on JDK 9 2017-09-18 18:01:05 +03:00
Alexander Udalov
28b4a372d2 Remove deprecated API from package kotlin.reflect
This is needed to avoid the split package problem on Java 9 (KT-19258):
both kotlin-stdlib.jar and kotlin-reflect.jar export the package
kotlin.reflect
2017-09-18 18:01:05 +03:00
Alexander Udalov
45be5e971d Decrease resolution priority of declarations from kotlin-stdlib-jre7/8
In order to allow "overload resolution ambiguity" when both
kotlin-stdlib-jre7/8 and kotlin-stdlib-jdk7/8 are in the dependencies
2017-09-18 18:01:04 +03:00
Alexander Udalov
f8b5e276bc Add test on compiling against kotlin.stdlib.jdk7/8 on JDK 9 2017-09-18 18:01:03 +03:00
Alexander Udalov
12cb4ffde5 Move internal declarations in kotlin-stdlib-jdk7/8 to other packages
- in kotlin-stdlib-jdk7, package kotlin.internal -> kotlin.internal.jdk7
- in kotlin-stdlib-jdk8, package kotlin.internal -> kotlin.internal.jdk8
2017-09-18 18:01:02 +03:00
Alexander Udalov
1fd5e25bb3 Restore kotlin-stdlib-jre7/8 libraries 2017-09-18 18:01:02 +03:00
Alexander Udalov
fa06b74440 Introduce kotlin-stdlib-jdk7/8 libraries, deprecate kotlin-stdlib-jre7/8
The idea is to keep all declarations in the same packages from Kotlin's
point of view, but use JvmPackageName annotation to move them to another
JVM package, to avoid the split package problem which is otherwise
unsolvable when using module path on Java 9 (KT-19258).

In this commit, kotlin-stdlib-jre7/8 are moved to kotlin-stdlib-jdk7/8
and in the subsequent commit, -jre7/8 are restored. This is done in
order to make Git recognize this as a file move to preserve history
2017-09-18 18:01:01 +03:00
Alexander Udalov
4d2c2c39c2 Update copyrights in kotlin-stdlib-jre7/8 sources 2017-09-18 18:01:00 +03:00
Alexander Udalov
5e6b195551 Revert "Temporarily remove JvmPackageName and tests, but keep the implementation"
This reverts commit 9ae6feb2c5.
2017-09-18 18:00:59 +03:00
Alexander Udalov
adaa4da502 Revert "Temporarily remove isInitialized and tests, but keep the implementation"
This reverts commit 234148518e.
2017-09-18 18:00:58 +03:00
Ilya Gorbunov
6f98973786 Refactor: use the same arraybuffer to compute double hashcode 2017-09-18 18:00:58 +03:00
Ilya Gorbunov
e82eb7bc87 Detect endianness when reinterpreting Float64 as two Int32
#KT-18264

Use Int32Array instead of Uint32Array since ints are required to be singed.
2017-09-18 18:00:57 +03:00
Ilya Gorbunov
7c51e305d0 Implement in JS nextUp(), nextDown(), nextTowards() and ulp extensions
#KT-4900
2017-09-18 18:00:56 +03:00
Ilya Gorbunov
eae7e959e8 Make withSign(NaN) behave as in JVM
#KT-4900

Where only the sign of the result is undefined, but the absolute value is unchanged.
2017-09-18 18:00:55 +03:00
Ilya Gorbunov
a94843cdd9 Provide Double and Float bit conversion functions as extensions in JS and Common
Instance extension: Double/Float.toBits/toRawBits
Companion extension: Double/Float.Companion.fromBits

#KT-18264 Fixed
2017-09-18 18:00:55 +03:00
Ilya Gorbunov
7e9c487073 Introduce inverse hyperbolic functions
#KT-4900

Improve accuracy of JS polyfills of hyperbolic functions and expm1/log1p
2017-09-18 18:00:54 +03:00
Alexey Sedunov
5919f5e2b3 Do not overwrite facet settings in Module.languageVersionSettings 2017-09-18 18:00:53 +03:00
Mikhael Bogdanov
c6511f465b Switch warning to error for java-default method calls within 1.6 target
#KT-15825 Fixed

(cherry picked from commit 9b29ebb)
2017-09-18 18:00:53 +03:00
Ilya Gorbunov
e1ae00cdf4 Minor fixes in logarithm functions docs 2017-09-18 18:00:52 +03:00
Ilya Gorbunov
17826efbf6 Annotate new API with SinceKotlin, provide common headers
#KT-4900

Also update binary API dump.
2017-09-18 18:00:51 +03:00
Ilya Gorbunov
fb673c4c9f Deprecate kotlin.js.Math object, rename kotlin.math.kt to just math.kt 2017-09-18 18:00:50 +03:00
Ilya Gorbunov
77faa8659d Integer math functions and tests for them
#KT-4900
2017-09-18 18:00:50 +03:00
Ilya Gorbunov
d986a20e42 Float Math API
#KT-4900
2017-09-18 18:00:49 +03:00
Ilya Gorbunov
39b103ba9c JVM-specific math functions and tests
#KT-4900
2017-09-18 18:00:48 +03:00
Ilya Gorbunov
7672b65c5f Provide Double and Float bit conversion functions as extensions
Instance extension: Double/Float.toBits/toRawBits
Companion extension: Double/Float.Companion.fromBits

 #KT-18264 Fixed
2017-09-18 18:00:48 +03:00
Ilya Gorbunov
2a4c21908b Rename log to ln, log1p to ln1p, keep pow only as extension
#KT-4900
2017-09-18 18:00:47 +03:00
Ilya Gorbunov
018cd25f6d Rename sgn to sign, add docs and tests
#KT-4900
2017-09-18 18:00:46 +03:00
Ilya Gorbunov
774ee74812 Use HALF_EVEN rounding mode for round()
Add docs and tests for rounding.

 #KT-4900
2017-09-18 18:00:45 +03:00
Ilya Gorbunov
759bfb5869 Common math tests and document for trigonometric functions and powers.
#KT-4900
2017-09-18 18:00:45 +03:00
Ilya Gorbunov
5516924430 Draft common math API with top-level functions and constants in kotlin.math package
#KT-4900
2017-09-18 18:00:44 +03:00
Ilya Gorbunov
24b2dd0166 Provide polyfills for missing ES6 math functions
#KT-4900

Rename math.kt to js.math.kt
2017-09-18 18:00:43 +03:00
Ilya Gorbunov
e87cf00d7b windowed function: add default parameters, drop or keep partial windows, KEEP-11
Make step default to 1.
Add partialWindows boolean parameter defaulting to false to control
whether to keep partial windows in the end.
2017-09-18 18:00:43 +03:00
Ilya Gorbunov
02d006eafa Rename pairwise to zipWithNext, KEEP-11 2017-09-18 18:00:42 +03:00
Ilya Gorbunov
b6a9e6fc0c Update binary api dump, rearrage bignumbers tests 2017-09-18 18:00:41 +03:00
Ilya Gorbunov
765adaef0a Add missing api: radix overloads, mathContext and scale overloads, orNull overloads
Move string-to-number conversions and their tests near to existing ones

Add documentation and copyrights.
2017-09-18 18:00:40 +03:00
voddan
cd22050cda KEEP-49: extending Kotlin API for BigInteger and BigDecimal 2017-09-18 18:00:40 +03:00
Anton Bannykh
3dc4bc284a JS: enable TypedArrays by default 2017-09-18 18:00:39 +03:00
Ilya Gorbunov
cec91bfd47 Temporary make 'implement' dependency transient 2017-09-18 18:00:38 +03:00
Ilya Gorbunov
89e0797d63 Provide MutableList.fill for JS, annotate new API with @SinceKotlin
#KT-8823 #KT-9010
2017-09-18 18:00:35 +03:00
Ilya Gorbunov
c41cae6264 Introduce MutableList.fill and shuffle/shuffled extensions for JVM only
'shuffle' and 'fill' are inline only, but 'shuffled' is not.

#KT-8823 Fixed
#KT-9010 Fixed
2017-09-18 17:59:43 +03:00
Ilya Gorbunov
64169a5b02 Make Regex class serializable on JVM
#KT-16447 Fixed

Refactor helper functions for serialization tests.
2017-09-18 17:59:42 +03:00
Ilya Gorbunov
fb10690690 Docs and samples for 'windowed' function 2017-09-18 17:59:41 +03:00
Ilya Gorbunov
4f1a483c22 Docs and samples for 'chunked' function 2017-09-18 17:59:41 +03:00
Ilya Gorbunov
a7d17eb24c Docs and samples for 'pairwise' function 2017-09-18 17:59:40 +03:00
Ilya Gorbunov
a035c2beb3 Minor refactoring in RingBuffer 2017-09-18 17:59:39 +03:00
Ilya Gorbunov
be1715cd59 Optimize 'windowed' and 'chunked' for char sequences, iterables and sequences 2017-09-18 17:59:38 +03:00
Ilya Gorbunov
03dcbcaf8d Add tests for windowed and chunked, fix precondition checks 2017-09-18 17:59:38 +03:00
Ilya Gorbunov
0e57fa3a82 Generate 'chunked' and 'windowed' signatures and delegating implementations
Add implementations of windowed.
2017-09-18 17:59:37 +03:00
Sergey Mashkov
120ab10d79 Sliding window implementation helper utilities 2017-09-18 17:59:36 +03:00
Ilya Gorbunov
e320104016 Introduce 'pairwise' function, KEEP-11 2017-09-18 17:59:35 +03:00
Mikhael Bogdanov
c5353f97c8 Move object initialization from <init> to <clinit>
Codegen generates static backing fields for object properties.
  They are initialized in class constructor but some of them are final static
  and such access is prohibited in specification but it's allowed in
  java bytecode <= 1.8. Such access in 1.9 bytecode cause
  "IllegalAccessError: Update to static final field Object.INSTANCE
  attempted from a different method (<init>) than the initializer method <clinit>"

  Added additional hidden field in interface companion to pass out
  companion instance from <clinit>.

 #KT-15894 Fixed
2017-09-18 17:59:35 +03:00
Ilya Gorbunov
dbc3891418 Remove "EXPERIMENTAL" from 1.2 version description in tests and gradle options 2017-09-18 17:59:34 +03:00
Ilya Gorbunov
f41a48f11a Set 1.2-SNAPSHOT in maven build 2017-09-18 17:59:33 +03:00
Ilya Gorbunov
81dc100276 Set 1.2-SNAPSHOT in gradle build 2017-09-18 17:59:32 +03:00
Ilya Gorbunov
b68ac868f5 Set LATEST_STABLE language version and current version of stdlib to 1.2, set IS_PRE_RELEASE 2017-09-18 17:59:32 +03:00
316 changed files with 11978 additions and 4520 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -32,6 +32,8 @@
<excludeFolder url="file://$MODULE_DIR$/libraries/kotlin.test/jvm/build" />
<excludeFolder url="file://$MODULE_DIR$/libraries/stdlib/build" />
<excludeFolder url="file://$MODULE_DIR$/libraries/stdlib/common/build" />
<excludeFolder url="file://$MODULE_DIR$/libraries/stdlib/jdk7/build" />
<excludeFolder url="file://$MODULE_DIR$/libraries/stdlib/jdk8/build" />
<excludeFolder url="file://$MODULE_DIR$/libraries/stdlib/jre7/build" />
<excludeFolder url="file://$MODULE_DIR$/libraries/stdlib/jre8/build" />
<excludeFolder url="file://$MODULE_DIR$/libraries/stdlib/js/build" />
@@ -83,4 +85,4 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
</module>

View File

@@ -34,7 +34,7 @@ public class FieldInfo {
}
if (isNonCompanionObject(classDescriptor) || CompanionObjectMapping.INSTANCE.isMappedIntrinsicCompanionObject(classDescriptor)) {
return createSingletonViaInstance(classDescriptor, typeMapper);
return createSingletonViaInstance(classDescriptor, typeMapper, JvmAbi.INSTANCE_FIELD);
}
ClassDescriptor ownerDescriptor = DescriptorUtils.getParentOfType(classDescriptor, ClassDescriptor.class);
@@ -46,10 +46,11 @@ public class FieldInfo {
@NotNull
public static FieldInfo createSingletonViaInstance(
@NotNull ClassDescriptor classDescriptor,
@NotNull KotlinTypeMapper typeMapper
@NotNull KotlinTypeMapper typeMapper,
@NotNull String name
) {
Type type = typeMapper.mapType(classDescriptor);
return new FieldInfo(type, type, JvmAbi.INSTANCE_FIELD, true);
return new FieldInfo(type, type, name, true);
}
@NotNull

View File

@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.config.LanguageFeature;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
import org.jetbrains.kotlin.lexer.KtTokens;
import org.jetbrains.kotlin.load.java.JvmAbi;
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode;
import org.jetbrains.kotlin.name.ClassId;
@@ -77,6 +76,7 @@ import static org.jetbrains.kotlin.codegen.CodegenUtilKt.isNonGenericToArray;
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.*;
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.enumEntryNeedSubclass;
import static org.jetbrains.kotlin.codegen.inline.InlineCodegenUtils2Kt.initDefaultSourceMappingIfNeeded;
import static org.jetbrains.kotlin.load.java.JvmAbi.*;
import static org.jetbrains.kotlin.resolve.BindingContextUtils.getDelegationConstructorCall;
import static org.jetbrains.kotlin.resolve.BindingContextUtils.getNotNull;
import static org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.descriptorToDeclaration;
@@ -354,6 +354,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
protected void generateSyntheticPartsAfterBody() {
generateFieldForSingleton();
initializeObjects();
generateCompanionObjectBackingFieldCopies();
generateTraitMethods();
@@ -811,21 +813,21 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
private void generateFieldForSingleton() {
if (isCompanionObjectInInterfaceNotIntrinsic(descriptor)) {
StackValue.Field field = StackValue.createSingletonViaInstance(descriptor, typeMapper, HIDDEN_INSTANCE_FIELD);
//hidden instance in interface companion
v.newField(JvmDeclarationOriginKt.OtherOrigin(descriptor),
ACC_SYNTHETIC | ACC_STATIC | ACC_FINAL, field.name, field.type.getDescriptor(), null, null);
}
if (isEnumEntry(descriptor) || isCompanionObject(descriptor)) return;
if (isNonCompanionObject(descriptor)) {
StackValue.Field field = StackValue.singletonViaInstance(descriptor, typeMapper);
StackValue.Field field = StackValue.createSingletonViaInstance(descriptor, typeMapper, INSTANCE_FIELD);
v.newField(JvmDeclarationOriginKt.OtherOriginFromPure(myClass),
ACC_PUBLIC | ACC_STATIC | ACC_FINAL,
field.name, field.type.getDescriptor(), null, null);
if (!state.getClassBuilderMode().generateBodies) return;
// Invoke the object constructor but ignore the result because INSTANCE will be initialized in the first line of <init>
InstructionAdapter v = createOrGetClInitCodegen().v;
markLineNumberForElement(element.getPsiOrParent(), v);
v.anew(classAsmType);
v.invokespecial(classAsmType.getInternalName(), "<init>", "()V", false);
return;
}
@@ -853,6 +855,60 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
}
private void initializeObjects() {
if (!DescriptorUtils.isObject(descriptor)) return;
if (!state.getClassBuilderMode().generateBodies) return;
boolean isNonCompanionObject = isNonCompanionObject(descriptor);
boolean isInterfaceCompanion = isCompanionObjectInInterfaceNotIntrinsic(descriptor);
boolean isMappedIntrinsicCompanionObject = isMappedIntrinsicCompanionObject(descriptor);
if (isNonCompanionObject || isInterfaceCompanion || isMappedIntrinsicCompanionObject) {
ExpressionCodegen clInitCodegen = createOrGetClInitCodegen();
InstructionAdapter v = clInitCodegen.v;
markLineNumberForElement(element.getPsiOrParent(), v);
v.anew(classAsmType);
v.dup();
v.invokespecial(classAsmType.getInternalName(), "<init>", "()V", false);
//local0 emulates this in object constructor
int local0Index = clInitCodegen.getFrameMap().enterTemp(classAsmType);
assert local0Index == 0 : "Local variable with index 0 in clInit should be used only for singleton instance keeping";
StackValue.Local local0 = StackValue.local(0, classAsmType);
local0.store(StackValue.onStack(classAsmType), clInitCodegen.v);
StackValue.Field singleton =
StackValue.createSingletonViaInstance(
descriptor, typeMapper, isInterfaceCompanion ? HIDDEN_INSTANCE_FIELD : INSTANCE_FIELD
);
singleton.store(local0, clInitCodegen.v);
generateInitializers(clInitCodegen);
if (isInterfaceCompanion) {
//initialize singleton instance in outer by hidden instance
StackValue.singleton(descriptor, typeMapper).store(
singleton, getParentCodegen().createOrGetClInitCodegen().v, true
);
}
}
else if (isCompanionObjectWithBackingFieldsInOuter(descriptor)) {
ImplementationBodyCodegen parentCodegen = (ImplementationBodyCodegen) getParentCodegen();
ExpressionCodegen parentClInitCodegen = parentCodegen.createOrGetClInitCodegen();
InstructionAdapter parentVisitor = parentClInitCodegen.v;
FunctionDescriptor constructor = (FunctionDescriptor) parentCodegen.context.accessibleDescriptor(
CollectionsKt.single(descriptor.getConstructors()), /* superCallExpression = */ null
);
parentCodegen.generateMethodCallTo(constructor, null, parentVisitor);
StackValue instance = StackValue.onStack(parentCodegen.typeMapper.mapClass(descriptor));
StackValue.singleton(descriptor, parentCodegen.typeMapper).store(instance, parentVisitor, true);
generateInitializers(parentClInitCodegen);
}
else {
assert false : "Unknown object type: " + descriptor;
}
}
private void generateCompanionObjectBackingFieldCopies() {
if (companionObjectPropertiesToCopy == null) return;
@@ -900,17 +956,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
field.store(property, codegen.v);
}
private void generateCompanionObjectInitializer(@NotNull ClassDescriptor companionObject) {
ExpressionCodegen codegen = createOrGetClInitCodegen();
FunctionDescriptor constructor = (FunctionDescriptor) context.accessibleDescriptor(
CollectionsKt.single(companionObject.getConstructors()), /* superCallExpression = */ null
);
generateMethodCallTo(constructor, null, codegen.v);
StackValue instance = StackValue.onStack(typeMapper.mapClass(companionObject));
StackValue.singleton(companionObject, typeMapper).store(instance, codegen.v, true);
}
private void generatePrimaryConstructor(DelegationFieldsInfo delegationFieldsInfo) {
if (isInterface(descriptor) || isAnnotationClass(descriptor)) return;
@@ -978,10 +1023,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
generateDelegatorToConstructorCall(iv, codegen, constructorDescriptor,
getDelegationConstructorCall(bindingContext, constructorDescriptor));
if (isNonCompanionObject(descriptor)) {
StackValue.singletonViaInstance(descriptor, typeMapper).store(StackValue.LOCAL_0, iv);
}
for (KtSuperTypeListEntry specifier : myClass.getSuperTypeListEntries()) {
if (specifier instanceof KtDelegatedSuperTypeEntry) {
genCallToDelegatorByExpressionSpecifier(iv, codegen, (KtDelegatedSuperTypeEntry) specifier, fieldsInfo);
@@ -1003,18 +1044,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
curParam++;
}
if (isCompanionObject(descriptor)) {
ImplementationBodyCodegen parentCodegen = (ImplementationBodyCodegen) getParentCodegen();
parentCodegen.generateCompanionObjectInitializer(descriptor);
}
if (JvmAbi.isCompanionObjectWithBackingFieldsInOuter(descriptor)) {
generateInitializers(((ImplementationBodyCodegen) getParentCodegen())::createOrGetClInitCodegen);
}
else {
//object initialization was moved to initializeObjects()
if (!isObject(descriptor)) {
generateInitializers(codegen);
}
iv.visitInsn(RETURN);
}
@@ -1159,7 +1192,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (asmType == null) continue;
result.addField((KtDelegatedSuperTypeEntry) specifier, asmType, JvmAbi.DELEGATE_SUPER_FIELD_PREFIX + n);
result.addField((KtDelegatedSuperTypeEntry) specifier, asmType, DELEGATE_SUPER_FIELD_PREFIX + n);
}
n++;
}

View File

@@ -608,8 +608,8 @@ public abstract class StackValue {
return field(FieldInfo.createForSingleton(classDescriptor, typeMapper), none());
}
public static Field singletonViaInstance(ClassDescriptor classDescriptor, KotlinTypeMapper typeMapper) {
return field(FieldInfo.createSingletonViaInstance(classDescriptor, typeMapper), none());
public static Field createSingletonViaInstance(@NotNull ClassDescriptor classDescriptor, @NotNull KotlinTypeMapper typeMapper, @NotNull String name) {
return field(FieldInfo.createSingletonViaInstance(classDescriptor, typeMapper, name), none());
}
public static StackValue operation(Type type, Function1<InstructionAdapter, Unit> lambda) {

View File

@@ -74,7 +74,8 @@ class BuiltInsSerializer(dependOnOldBuiltIns: Boolean) : MetadataSerializer(depe
}
private fun createMessageCollector() = object : GroupingMessageCollector(
PrintingMessageCollector(System.err, MessageRenderer.PLAIN_RELATIVE_PATHS, /* verbose = */ false)
PrintingMessageCollector(System.err, MessageRenderer.PLAIN_RELATIVE_PATHS, false),
false
) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
// Only report diagnostics without a particular location because there's plenty of errors in built-in sources

View File

@@ -44,4 +44,8 @@ abstract class CommonToolArguments : Freezable(), Serializable {
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-nowarn", description = "Generate no warnings")
var suppressWarnings: Boolean by FreezableVar(false)
@GradleOption(DefaultValues.BooleanFalseDefault::class)
@Argument(value = "-Werror", description = "Report an error if there are any warnings")
var warningsAsErrors: Boolean by FreezableVar(false)
}

View File

@@ -35,11 +35,14 @@ public enum CompilerMessageSeverity {
*/
OUTPUT;
public static final EnumSet<CompilerMessageSeverity> ERRORS = EnumSet.of(ERROR, EXCEPTION);
public static final EnumSet<CompilerMessageSeverity> VERBOSE = EnumSet.of(LOGGING);
public boolean isError() {
return ERRORS.contains(this);
return this == EXCEPTION || this == ERROR;
}
public boolean isWarning() {
return this == STRONG_WARNING || this == WARNING;
}
@NotNull

View File

@@ -24,16 +24,19 @@ import org.jetbrains.annotations.Nullable;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class GroupingMessageCollector implements MessageCollector {
private final MessageCollector delegate;
private final boolean treatWarningsAsErrors;
// Note that the key in this map can be null
private final Multimap<CompilerMessageLocation, Message> groupedMessages = LinkedHashMultimap.create();
public GroupingMessageCollector(@NotNull MessageCollector delegate) {
public GroupingMessageCollector(@NotNull MessageCollector delegate, boolean treatWarningsAsErrors) {
this.delegate = delegate;
this.treatWarningsAsErrors = treatWarningsAsErrors;
}
@Override
@@ -57,17 +60,29 @@ public class GroupingMessageCollector implements MessageCollector {
@Override
public boolean hasErrors() {
return hasExplicitErrors() || (treatWarningsAsErrors && hasWarnings());
}
private boolean hasExplicitErrors() {
return groupedMessages.entries().stream().anyMatch(entry -> entry.getValue().severity.isError());
}
private boolean hasWarnings() {
return groupedMessages.entries().stream().anyMatch(entry -> entry.getValue().severity.isWarning());
}
public void flush() {
boolean hasErrors = hasErrors();
boolean hasExplicitErrors = hasExplicitErrors();
if (treatWarningsAsErrors && !hasExplicitErrors && hasWarnings()) {
report(CompilerMessageSeverity.ERROR, "warnings found and -Werror specified", null);
}
List<CompilerMessageLocation> sortedKeys =
CollectionsKt.sortedWith(groupedMessages.keySet(), Comparator.nullsFirst(CompilerMessageLocationComparator.INSTANCE));
for (CompilerMessageLocation location : sortedKeys) {
for (Message message : groupedMessages.get(location)) {
if (!hasErrors || message.severity.isError() || message.severity == CompilerMessageSeverity.STRONG_WARNING) {
if (!hasExplicitErrors || message.severity.isError() || message.severity == CompilerMessageSeverity.STRONG_WARNING) {
delegate.report(message.severity, message.message, message.location);
}
}

View File

@@ -65,7 +65,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> extends CLI
@NotNull
@Override
public ExitCode execImpl(@NotNull MessageCollector messageCollector, @NotNull Services services, @NotNull A arguments) {
GroupingMessageCollector groupingCollector = new GroupingMessageCollector(messageCollector);
GroupingMessageCollector groupingCollector = new GroupingMessageCollector(messageCollector, arguments.getWarningsAsErrors());
CompilerConfiguration configuration = new CompilerConfiguration();
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, groupingCollector);

View File

@@ -81,7 +81,7 @@ abstract class CLITool<A : CommonToolArguments> {
fun exec(messageCollector: MessageCollector, services: Services, arguments: A): ExitCode {
printVersionIfNeeded(messageCollector, arguments)
val fixedMessageCollector = if (arguments.suppressWarnings) {
val fixedMessageCollector = if (arguments.suppressWarnings && !arguments.warningsAsErrors) {
FilteringMessageCollector(messageCollector, Predicate.isEqual(CompilerMessageSeverity.WARNING))
}
else {

View File

@@ -28,7 +28,8 @@ class ReplTerminalDiagnosticMessageHolder : MessageCollectorBasedReporter, Diagn
private val outputStream = ByteArrayOutputStream()
override val messageCollector: GroupingMessageCollector = GroupingMessageCollector(
PrintingMessageCollector(PrintStream(outputStream), MessageRenderer.WITHOUT_PATHS, false)
PrintingMessageCollector(PrintStream(outputStream), MessageRenderer.WITHOUT_PATHS, false),
false
)
override val renderedDiagnostics: String

View File

@@ -115,7 +115,7 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
"Please make explicit overrides (abstract or concrete) for the following non-abstract members of ''{1}'': {2}",
NAME, NAME, STRING);
MAP.put(DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET, "Super calls to Java default methods are deprecated in JVM target 1.6. Recompile with '-jvm-target 1.8'");
MAP.put(DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET, "Super calls to Java default methods are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8'");
MAP.put(INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET, "Calls to static methods in Java interfaces are deprecated in JVM target 1.6. Recompile with '-jvm-target 1.8'");
MAP.put(INLINE_FROM_HIGHER_PLATFORM, "Cannot inline bytecode built with {0} into bytecode that is being built with {1}. Please specify proper ''-jvm-target'' option", STRING, STRING);

View File

@@ -96,7 +96,7 @@ public interface ErrorsJvm {
DiagnosticFactory3<PsiElement, DeclarationDescriptor, DeclarationDescriptor, String> TARGET6_INTERFACE_INHERITANCE = DiagnosticFactory3.create(ERROR);
DiagnosticFactory0<PsiElement> DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<PsiElement> DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET = DiagnosticFactory0.create(WARNING);
DiagnosticFactory2<PsiElement, String, String> INLINE_FROM_HIGHER_PLATFORM = DiagnosticFactory2.create(ERROR);

View File

@@ -276,7 +276,7 @@ public class DefaultErrorMessages {
MAP.put(ACTUAL_TYPE_ALIAS_WITH_USE_SITE_VARIANCE, "Right-hand side of actual type alias cannot contain use-site variance or star projections");
MAP.put(ACTUAL_TYPE_ALIAS_WITH_COMPLEX_SUBSTITUTION, "Type arguments in the right-hand side of actual type alias should be its type parameters in the same order, e.g. 'actual typealias Foo<A, B> = Bar<A, B>'");
MAP.put(NO_ACTUAL_FOR_EXPECT, "Expected {0} has no actual in module{1}{2}", DECLARATION_NAME_WITH_KIND,
MAP.put(NO_ACTUAL_FOR_EXPECT, "Expected {0} has no actual declaration in module{1}{2}", DECLARATION_NAME_WITH_KIND,
PLATFORM, PlatformIncompatibilityDiagnosticRenderer.TEXT);
MAP.put(ACTUAL_WITHOUT_EXPECT, "Actual {0} has no corresponding expected declaration{1}", DECLARATION_NAME_WITH_KIND,
PlatformIncompatibilityDiagnosticRenderer.TEXT);

View File

@@ -101,7 +101,7 @@ private fun StringBuilder.renderIncompatibilityInformation(
if (incompatibility is Incompatible.ClassScopes) {
append(indent)
append("No actuals are found for expected members listed below:")
append("No actual members are found for expected members listed below:")
mode.newLine(this)
renderIncompatibleClassScopes(incompatibility.unfulfilled, indent, context, mode)
}

View File

@@ -258,6 +258,7 @@ public interface BindingContext {
WritableSlice<FqNameUnsafe, ClassDescriptor> FQNAME_TO_CLASS_DESCRIPTOR = new BasicWritableSlice<>(DO_NOTHING, true);
WritableSlice<KtFile, PackageFragmentDescriptor> FILE_TO_PACKAGE_FRAGMENT = Slices.createSimpleSlice();
WritableSlice<FqName, Collection<KtFile>> PACKAGE_TO_FILES = Slices.createSimpleSlice();
WritableSlice<KtBinaryExpressionWithTypeRHS, Boolean> CAST_TYPE_USED_AS_EXPECTED_TYPE = Slices.createSimpleSlice();
WritableSlice<KtFunction, KotlinResolutionCallbacksImpl.LambdaInfo> NEW_INFERENCE_LAMBDA_INFO = new BasicWritableSlice<>(DO_NOTHING);

View File

@@ -20,11 +20,16 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.ReflectionTypes
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalTypeOrSubtype
import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.*
@@ -39,6 +44,7 @@ import org.jetbrains.kotlin.resolve.calls.context.ResolutionResultsCache
import org.jetbrains.kotlin.resolve.calls.context.TemporaryTraceAndCache
import org.jetbrains.kotlin.resolve.calls.inference.*
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPosition
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.RECEIVER_POSITION
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.VALUE_PARAMETER_POSITION
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ValidityConstraintForConstituentType
@@ -53,12 +59,16 @@ import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE
import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.ResolveConstruct
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
import org.jetbrains.kotlin.types.typeUtil.contains
import org.jetbrains.kotlin.types.typeUtil.makeNullable
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
private val SPECIAL_FUNCTION_NAMES = ResolveConstruct.values().map { it.specialFunctionName }.toSet()
class GenericCandidateResolver(
private val argumentTypeResolver: ArgumentTypeResolver,
private val coroutineInferenceSupport: CoroutineInferenceSupport
private val coroutineInferenceSupport: CoroutineInferenceSupport,
private val languageVersionSettings: LanguageVersionSettings
) {
fun <D : CallableDescriptor> inferTypeArguments(context: CallCandidateResolutionContext<D>): ResolutionStatus {
val candidateCall = context.candidateCall
@@ -116,11 +126,68 @@ class GenericCandidateResolver(
// Solution
val hasContradiction = constraintSystem.status.hasContradiction()
if (!hasContradiction) {
addExpectedTypeForExplicitCast(context, builder)
return INCOMPLETE_TYPE_INFERENCE
}
return OTHER_ERROR
}
private fun ConstraintSystem.Builder.typeInSystem(call: Call, type: KotlinType?): KotlinType? =
type?.let {
typeVariableSubstitutors[call.toHandle()]?.substitute(it, Variance.INVARIANT)
}
private fun FunctionDescriptor.isFunctionForExpectTypeFromCastFeature(): Boolean {
val typeParameter = typeParameters.singleOrNull() ?: return false
val returnType = returnType ?: return false
if (returnType is DeferredType && returnType.isComputing) return false
if (returnType.constructor != typeParameter.typeConstructor) return false
fun KotlinType.isBadType() = contains { it.constructor == typeParameter.typeConstructor }
if (valueParameters.any { it.type.isBadType() } || extensionReceiverParameter?.type?.isBadType() == true) return false
return true
}
private fun addExpectedTypeForExplicitCast(
context: CallCandidateResolutionContext<*>,
builder: ConstraintSystem.Builder
) {
if (!languageVersionSettings.supportsFeature(LanguageFeature.ExpectedTypeFromCast)) return
if (context.candidateCall is VariableAsFunctionResolvedCall) return
val candidateDescriptor = context.candidateCall.candidateDescriptor.safeAs<FunctionDescriptor>() ?: return
val binaryParent = getBinaryWithTypeParent(context.call.calleeExpression) ?: return
val operationType = binaryParent.operationReference.getReferencedNameElementType().takeIf {
it == KtTokens.AS_KEYWORD || it == KtTokens.AS_SAFE
} ?: return
val leftType = context.trace.get(BindingContext.TYPE, binaryParent.right ?: return) ?: return
val expectedType = if (operationType == KtTokens.AS_SAFE) leftType.makeNullable() else leftType
if (context.candidateCall.call.typeArgumentList != null || !candidateDescriptor.isFunctionForExpectTypeFromCastFeature()) return
val typeInSystem = builder.typeInSystem(context.call, candidateDescriptor.returnType ?: return) ?: return
context.trace.record(BindingContext.CAST_TYPE_USED_AS_EXPECTED_TYPE, binaryParent)
builder.addSubtypeConstraint(typeInSystem, expectedType, ConstraintPositionKind.SPECIAL.position())
}
private fun getBinaryWithTypeParent(calleeExpression: KtExpression?): KtBinaryExpressionWithTypeRHS? {
val callExpression = calleeExpression?.parent.safeAs<KtCallExpression>() ?: return null
val parent = callExpression.parent
return when (parent) {
is KtBinaryExpressionWithTypeRHS -> parent
is KtQualifiedExpression -> parent.parent.safeAs<KtBinaryExpressionWithTypeRHS>().takeIf { parent.selectorExpression == callExpression }
else -> null
}
}
private fun addValidityConstraintsForConstituentTypes(builder: ConstraintSystem.Builder, type: KotlinType) {
val typeConstructor = type.constructor
if (typeConstructor.declarationDescriptor is TypeParameterDescriptor) return

View File

@@ -366,6 +366,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
) {
if (actualType == null || noExpectedType(targetType) || KotlinTypeKt.isError(targetType)) return;
if (Boolean.TRUE.equals(context.trace.get(BindingContext.CAST_TYPE_USED_AS_EXPECTED_TYPE, expression))) return;
if (DynamicTypesKt.isDynamic(targetType)) {
KtTypeReference right = expression.getRight();
assert right != null : "We know target is dynamic, but RHS is missing";

View File

@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.resolve.calls.USE_NEW_INFERENCE
import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCast
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForTypeAliasObject
import org.jetbrains.kotlin.resolve.calls.util.isLowPriorityFromStdlibJre7Or8
import org.jetbrains.kotlin.resolve.descriptorUtil.HIDES_MEMBERS_NAME_LIST
import org.jetbrains.kotlin.resolve.descriptorUtil.hasClassValueDescriptor
import org.jetbrains.kotlin.resolve.descriptorUtil.hasHidesMembersAnnotation
@@ -59,7 +60,9 @@ internal abstract class AbstractScopeTowerLevel(
diagnostics.add(ErrorDescriptorDiagnostic)
}
else {
if (descriptor.hasLowPriorityInOverloadResolution()) diagnostics.add(LowPriorityDescriptorDiagnostic)
if (descriptor.hasLowPriorityInOverloadResolution() || descriptor.isLowPriorityFromStdlibJre7Or8()) {
diagnostics.add(LowPriorityDescriptorDiagnostic)
}
if (dispatchReceiverSmartCastType != null) diagnostics.add(UsedSmartCastForDispatchReceiver(dispatchReceiverSmartCastType))
if (!USE_NEW_INFERENCE) {

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve.calls.util
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.getSinceKotlinAnnotation
private val kotlin: FqName = KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME
private val kotlinText: FqName = KotlinBuiltIns.TEXT_PACKAGE_FQ_NAME
private val kotlinCollections: FqName = KotlinBuiltIns.COLLECTIONS_PACKAGE_FQ_NAME
private val kotlinStreams: FqName = kotlin.child(Name.identifier("streams"))
private val use: Name = Name.identifier("use")
private val get: Name = Name.identifier("get")
private val getOrDefault: Name = Name.identifier("getOrDefault")
private val remove: Name = Name.identifier("remove")
// We treat all declarations in deprecated libraries kotlin-stdlib-jre7 and kotlin-stdlib-jre8 as if they were
// annotated with @LowPriorityInOverloadResolution.
// This is needed in order to avoid reporting "overload resolution ambiguity" in case when there's both kotlin-stdlib-jreN and
// kotlin-stdlib-jdkN in dependencies, to allow smooth migration from the former to the latter. The ambiguity here would be incorrect
// because there's really no ambiguity in the bytecode since all declarations in -jdk7/8 have been moved to another JVM package.
// We locate declarations in kotlin-stdlib-jre{7,8} by FQ name and @SinceKotlin annotation value, which should be 1.1.
fun CallableDescriptor.isLowPriorityFromStdlibJre7Or8(): Boolean {
val containingPackage = containingDeclaration as? PackageFragmentDescriptor ?: return false
val packageFqName = containingPackage.fqName
if (!packageFqName.startsWith(KotlinBuiltIns.BUILT_INS_PACKAGE_NAME)) return false
val isFromStdlibJre7Or8 =
packageFqName == kotlin && name == use ||
packageFqName == kotlinText && name == get ||
packageFqName == kotlinCollections && (name == getOrDefault || name == remove) ||
packageFqName == kotlinStreams
if (!isFromStdlibJre7Or8) return false
val sinceKotlin = getSinceKotlinAnnotation() ?: return false
val version = sinceKotlin.allValueArguments.values.singleOrNull()?.value as? String ?: return false
return version == LanguageVersion.KOTLIN_1_1.versionString
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,14 +27,14 @@ import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForTypeAlia
private val SINCE_KOTLIN_FQ_NAME = FqName("kotlin.SinceKotlin")
// TODO: use-site targeted annotations
internal fun DeclarationDescriptor.getSinceKotlinAnnotation(): AnnotationDescriptor? =
fun DeclarationDescriptor.getSinceKotlinAnnotation(): AnnotationDescriptor? =
annotations.findAnnotation(SINCE_KOTLIN_FQ_NAME)
/**
* @return true if the descriptor is accessible according to [languageVersionSettings], or false otherwise. The [actionIfInaccessible]
* callback is called with the version specified in the [SinceKotlin] annotation if the descriptor is inaccessible.
*/
internal fun DeclarationDescriptor.checkSinceKotlinVersionAccessibility(
fun DeclarationDescriptor.checkSinceKotlinVersionAccessibility(
languageVersionSettings: LanguageVersionSettings,
actionIfInaccessible: ((ApiVersion) -> Unit)? = null
): Boolean {

View File

@@ -8,4 +8,5 @@ where possible options include:
-nowarn Generate no warnings
-verbose Enable verbose logging output
-version Display compiler version
-Werror Report an error if there are any warnings
OK

View File

@@ -26,4 +26,5 @@ where possible options include:
-nowarn Generate no warnings
-verbose Enable verbose logging output
-version Display compiler version
-Werror Report an error if there are any warnings
OK

View File

@@ -1,3 +1,3 @@
error: unknown API version: 239.42
Supported API versions: 1.0, 1.1, 1.2 (EXPERIMENTAL), 1.3 (EXPERIMENTAL)
Supported API versions: 1.0, 1.1, 1.2
COMPILATION_ERROR

View File

@@ -23,4 +23,5 @@ where possible options include:
-nowarn Generate no warnings
-verbose Enable verbose logging output
-version Display compiler version
-Werror Report an error if there are any warnings
OK

View File

@@ -1,3 +1,3 @@
error: unknown language version: 239.42
Supported language versions: 1.0, 1.1, 1.2 (EXPERIMENTAL), 1.3 (EXPERIMENTAL)
Supported language versions: 1.0, 1.1, 1.2
COMPILATION_ERROR

4
compiler/testData/cli/jvm/werror.args vendored Normal file
View File

@@ -0,0 +1,4 @@
$TESTDATA_DIR$/werror.kt
-d
$TEMP_DIR$
-Werror

4
compiler/testData/cli/jvm/werror.kt vendored Normal file
View File

@@ -0,0 +1,4 @@
fun foo(s: String, t: String?) {
s!!
t?.toString()
}

5
compiler/testData/cli/jvm/werror.out vendored Normal file
View File

@@ -0,0 +1,5 @@
error: warnings found and -Werror specified
compiler/testData/cli/jvm/werror.kt:2:6: warning: unnecessary non-null assertion (!!) on a non-null receiver of type String
s!!
^
COMPILATION_ERROR

View File

@@ -0,0 +1,4 @@
$TESTDATA_DIR$/werrorWithExplicitError.kt
-d
$TEMP_DIR$
-Werror

View File

@@ -0,0 +1,5 @@
fun foo(s: String, t: String?) {
s!!
t?.toString()
t.length
}

View File

@@ -0,0 +1,4 @@
compiler/testData/cli/jvm/werrorWithExplicitError.kt:4:6: error: only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?
t.length
^
COMPILATION_ERROR

View File

@@ -0,0 +1,5 @@
$TESTDATA_DIR$/werrorWithNoWarn.kt
-d
$TEMP_DIR$
-Werror
-nowarn

View File

@@ -0,0 +1,4 @@
fun foo(s: String, t: String?) {
s!!
t?.toString()
}

View File

@@ -0,0 +1,5 @@
error: warnings found and -Werror specified
compiler/testData/cli/jvm/werrorWithNoWarn.kt:2:6: warning: unnecessary non-null assertion (!!) on a non-null receiver of type String
s!!
^
COMPILATION_ERROR

View File

@@ -0,0 +1,6 @@
$TESTDATA_DIR$/werrorWithStrongWarning.kt
-d
$TEMP_DIR$
-Werror
-cp
non-existing-path.jar

View File

@@ -0,0 +1,4 @@
fun foo(s: String, t: String?) {
s!!
t?.toString()
}

View File

@@ -0,0 +1,3 @@
warning: classpath entry points to a non-existent location: non-existing-path.jar
error: warnings found and -Werror specified
COMPILATION_ERROR

View File

@@ -0,0 +1,18 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// LANGUAGE_VERSION: 1.2
// FILE: foo.kt
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@file:JvmPackageName("jjj")
fun f(): String = "O"
val g: String? get() = "K"
inline fun i(block: () -> String) = block()
// FILE: bar.kt
fun box(): String = i { f() + g }

View File

@@ -0,0 +1,21 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// LANGUAGE_VERSION: 1.2
// FILE: foo.kt
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@file:JvmPackageName("baz.foo.quux.bar")
package foo.bar
fun f(): String = "O"
val g: String? get() = "K"
inline fun <T> i(block: () -> T): T = block()
// FILE: bar.kt
import foo.bar.*
fun box(): String = i { f() + g }

View File

@@ -0,0 +1,19 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// LANGUAGE_VERSION: 1.2
// FILE: foo.kt
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@file:JvmPackageName("jjj")
@file:JvmName("Foooo")
fun f(): String = "O"
val g: String? get() = "K"
inline fun i(block: () -> String) = block()
// FILE: bar.kt
fun box(): String = i { f() + g }

View File

@@ -0,0 +1,19 @@
var result = ""
class A {
companion object {
val prop = test()
fun test(): String {
result += "OK"
return result
}
}
}
fun box(): String {
if (A.prop != "OK") return "fail ${A.prop}"
return result
}

View File

@@ -0,0 +1,19 @@
var result = ""
interface A {
companion object {
val prop = test()
fun test(): String {
result += "OK"
return result
}
}
}
fun box(): String {
if (A.prop != "OK") return "fail ${A.prop}"
return result
}

View File

@@ -0,0 +1,15 @@
var result = ""
object A {
val prop = test()
fun test(): String {
result += "OK"
return result
}
}
fun box(): String {
if (A.prop != "OK") return "fail ${A.prop}"
return result
}

View File

@@ -0,0 +1,35 @@
// IGNORE_BACKEND: NATIVE
// LANGUAGE_VERSION: 1.2
// WITH_RUNTIME
open class Foo {
lateinit var bar: String
private lateinit var baz: String
fun test(): String {
val isBarInitialized: () -> Boolean = { this::bar.isInitialized }
if (isBarInitialized()) return "Fail 1"
bar = "bar"
if (!isBarInitialized()) return "Fail 2"
baz = "baz"
return InnerSubclass().testInner()
}
inner class InnerSubclass : Foo() {
fun testInner(): String {
// This is access to InnerSubclass.bar which is inherited from Foo.bar
if (this::bar.isInitialized) return "Fail 3"
bar = "OK"
if (!this::bar.isInitialized) return "Fail 4"
// This is access to Foo.bar declared lexically above
if (!this@Foo::bar.isInitialized) return "Fail 5"
return "OK"
}
}
}
fun box(): String {
return Foo().test()
}

View File

@@ -0,0 +1,21 @@
// IGNORE_BACKEND: NATIVE
// LANGUAGE_VERSION: 1.2
// WITH_RUNTIME
class Foo {
lateinit var bar: String
fun test(): String {
var state = 0
if (run { state++; this }::bar.isInitialized) return "Fail 1"
bar = "A"
if (!run { state++; this }::bar.isInitialized) return "Fail 3"
return if (state == 2) "OK" else "Fail: state=$state"
}
}
fun box(): String {
return Foo().test()
}

View File

@@ -0,0 +1,36 @@
// TARGET_BACKEND: JVM
// LANGUAGE_VERSION: 1.2
// WITH_RUNTIME
// FILE: J.java
public class J {
public static void deinitialize(Foo foo) {
foo.bar = null;
}
}
// FILE: main.kt
class Foo {
lateinit var bar: String
fun test(): String {
if (this::bar.isInitialized) return "Fail 1"
J.deinitialize(this)
if (this::bar.isInitialized) return "Fail 2"
bar = "A"
if (!this::bar.isInitialized) return "Fail 3"
J.deinitialize(this)
if (this::bar.isInitialized) return "Fail 4"
bar = "OK"
if (!this::bar.isInitialized) return "Fail 5"
return bar
}
}
fun box(): String {
return Foo().test()
}

View File

@@ -0,0 +1,12 @@
// IGNORE_BACKEND: NATIVE
// LANGUAGE_VERSION: 1.2
// WITH_RUNTIME
lateinit var bar: String
fun box(): String {
if (::bar.isInitialized) return "Fail 1"
bar = "OK"
if (!::bar.isInitialized) return "Fail 2"
return bar
}

View File

@@ -14,7 +14,7 @@ fun box(): String {
if (enclosingMethod != null) return "method: $enclosingMethod"
val enclosingConstructor = javaClass.getEnclosingConstructor()
if (enclosingConstructor == null) return "no enclosing constructor"
if (enclosingConstructor != null) return "field should be initialized in clInit"
val enclosingClass = javaClass.getEnclosingClass()
if (enclosingClass?.getName() != "O") return "enclosing class: $enclosingClass"

View File

@@ -0,0 +1,19 @@
// IGNORE_BACKEND: JS, NATIVE
// LANGUAGE_VERSION: 1.2
// WITH_RUNTIME
import kotlin.test.assertEquals
inline fun <reified T> foo(): T {
return T::class.java.getName() as T
}
fun box(): String {
val fooCall = foo() as String
assertEquals("java.lang.String", fooCall)
val safeFooCall = foo() as? String
assertEquals("java.lang.String", safeFooCall)
return "OK"
}

View File

@@ -0,0 +1,21 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// LANGUAGE_VERSION: 1.2
// FILE: 1.kt
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@file:JvmPackageName("baz.foo.quux.bar")
package foo.bar
fun f(): String = "O"
val g: String? get() = "K"
inline fun <T> i(block: () -> T): T = block()
// FILE: 2.kt
import foo.bar.*
fun box(): String = i { f() + g }

View File

@@ -49,7 +49,8 @@
"class": "PublicInterface$Companion",
"members": [
{"visibility": "private", "declaration": "constructor Companion()", "name": "<init>", "desc": "()V"},
{"visibility": "private", "declaration": "constructor Companion()", "name": "<init>", "desc": "(Lkotlin/jvm/internal/DefaultConstructorMarker;)V"}
{"visibility": "public", "declaration": "companion object", "name": "$$INSTANCE", "desc": "LPublicInterface$Companion;"},
{"visibility": "public", "declaration": "companion object", "name": "<clinit>", "desc": "()V"}
]
},
{
@@ -75,7 +76,8 @@
"class": "InternalInterface$Companion",
"members": [
{"visibility": "private", "declaration": "constructor Companion()", "name": "<init>", "desc": "()V"},
{"visibility": "private", "declaration": "constructor Companion()", "name": "<init>", "desc": "(Lkotlin/jvm/internal/DefaultConstructorMarker;)V"}
{"visibility": "public", "declaration": "companion object", "name": "$$INSTANCE", "desc": "LInternalInterface$Companion;"},
{"visibility": "public", "declaration": "companion object", "name": "<clinit>", "desc": "()V"}
]
},
{
@@ -101,7 +103,8 @@
"class": "InternalInterfacePrivateCompanion$Companion",
"members": [
{"visibility": "private", "declaration": "constructor Companion()", "name": "<init>", "desc": "()V"},
{"visibility": "private", "declaration": "constructor Companion()", "name": "<init>", "desc": "(Lkotlin/jvm/internal/DefaultConstructorMarker;)V"}
{"visibility": "private", "declaration": "companion object", "name": "$$INSTANCE", "desc": "LInternalInterfacePrivateCompanion$Companion;"},
{"visibility": "private", "declaration": "companion object", "name": "<clinit>", "desc": "()V"}
]
},
{
@@ -163,7 +166,8 @@
"class": "PrivateInterface$Companion",
"members": [
{"visibility": "private", "declaration": "constructor Companion()", "name": "<init>", "desc": "()V"},
{"visibility": "private", "declaration": "constructor Companion()", "name": "<init>", "desc": "(Lkotlin/jvm/internal/DefaultConstructorMarker;)V"}
{"visibility": "public", "declaration": "companion object", "name": "$$INSTANCE", "desc": "LPrivateInterface$Companion;"},
{"visibility": "public", "declaration": "companion object", "name": "<clinit>", "desc": "()V"}
]
},
{
@@ -189,7 +193,8 @@
"class": "PrivateInterfacePrivateCompanion$Companion",
"members": [
{"visibility": "private", "declaration": "constructor Companion()", "name": "<init>", "desc": "()V"},
{"visibility": "private", "declaration": "constructor Companion()", "name": "<init>", "desc": "(Lkotlin/jvm/internal/DefaultConstructorMarker;)V"}
{"visibility": "private", "declaration": "companion object", "name": "$$INSTANCE", "desc": "LPrivateInterfacePrivateCompanion$Companion;"},
{"visibility": "private", "declaration": "companion object", "name": "<clinit>", "desc": "()V"}
]
},
{

View File

@@ -11,6 +11,7 @@ open class Base {
fun foo() = "OK"
}
@kotlin.Suppress("DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET")
class C : Base(), IBase {
val lambda1 = {
super.foo()

View File

@@ -15,6 +15,7 @@ interface KInterface {
}
class Test : Simple {
@kotlin.Suppress("DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET")
fun bar(): String {
return super.test()
}

View File

@@ -13,12 +13,14 @@ interface KInterface : Test {
}
class KClass : Test {
@kotlin.Suppress("DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET")
fun ktest(): String {
return super.test() + test()
}
}
class KTClass : KInterface {
@kotlin.Suppress("DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET")
fun ktest(): String {
return super.test() + test()
}
@@ -27,6 +29,7 @@ class KTClass : KInterface {
fun box(): String {
val p = object : KInterface {
@kotlin.Suppress("DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET")
fun ktest(): String {
return super.test() + test()
}

View File

@@ -15,6 +15,7 @@ interface K2 : K1
interface K3 : K2
class C : K3 {
@kotlin.Suppress("DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET")
override fun foo() = super.foo()
}

View File

@@ -0,0 +1,26 @@
// IGNORE_BACKEND: NATIVE
// FILE: A.kt
// LANGUAGE_VERSION: 1.2
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@file:JvmPackageName("bar")
package foo
fun f() = "OK"
var v: Int = 1
inline fun i(block: () -> Unit) = block()
// FILE: B.kt
// LANGUAGE_VERSION: 1.2
import foo.*
fun box(): String {
v = 2
if (v != 2) return "Fail"
i { v = 3 }
if (v != 3) return "Fail"
return f()
}

View File

@@ -0,0 +1,19 @@
// IGNORE_BACKEND: NATIVE
// FILE: A.kt
// LANGUAGE_VERSION: 1.2
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@file:JvmPackageName("bar")
fun f() = "OK"
var v: Int = 1
// FILE: B.kt
// LANGUAGE_VERSION: 1.2
fun box(): String {
v = 2
if (v != 2) return "Fail"
return f()
}

View File

@@ -0,0 +1,23 @@
// IGNORE_BACKEND: NATIVE
// FILE: A.kt
// LANGUAGE_VERSION: 1.2
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@file:JvmPackageName("bar")
@file:JvmName("Baz")
package foo
fun f() = "OK"
var v: Int = 1
// FILE: B.kt
// LANGUAGE_VERSION: 1.2
import foo.*
fun box(): String {
v = 2
if (v != 2) return "Fail"
return f()
}

View File

@@ -0,0 +1,12 @@
// !LANGUAGE: +ExpectedTypeFromCast
fun foo() = 1
fun <T> foo() = foo() <!UNCHECKED_CAST!>as T<!>
fun <T> foo2(): T = TODO()
val test = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo2<!>().<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>plus<!>("") as String
fun <T> T.bar() = this
val barTest = "".bar() <!CAST_NEVER_SUCCEEDS!>as<!> Number

View File

@@ -0,0 +1,8 @@
package
public val barTest: kotlin.Number
public val test: kotlin.String
public fun foo(): kotlin.Int
public fun </*0*/ T> foo(): T
public fun </*0*/ T> foo2(): T
public fun </*0*/ T> T.bar(): T

View File

@@ -0,0 +1,20 @@
// !LANGUAGE: +ExpectedTypeFromCast
fun <T> foo(): T = TODO()
fun <V> id(value: V) = value
val asString = foo() as String
val viaId = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>id<!>(<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>()) as String
val insideId = id(foo() as String)
val asList = foo() as List<String>
val asStarList = foo() as List<*>
val safeAs = foo() as? String
val fromIs = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>() is String
val fromNoIs = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>() !is String

View File

@@ -0,0 +1,12 @@
package
public val asList: kotlin.collections.List<kotlin.String>
public val asStarList: kotlin.collections.List<*>
public val asString: kotlin.String
public val fromIs: kotlin.Boolean
public val fromNoIs: kotlin.Boolean
public val insideId: kotlin.String
public val safeAs: kotlin.String?
public val viaId: kotlin.String
public fun </*0*/ T> foo(): T
public fun </*0*/ V> id(/*0*/ value: V): V

View File

@@ -0,0 +1,16 @@
// !LANGUAGE: +ExpectedTypeFromCast
package pp
class A {
fun <T> foo(): T = TODO()
companion object {
fun <T> foo2(): T = TODO()
}
}
val x = A().foo() as String
val y = A.foo2() as String
val z = pp.A.foo2() as String

View File

@@ -0,0 +1,23 @@
package
package pp {
public val x: kotlin.String
public val y: kotlin.String
public val z: kotlin.String
public final class A {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun </*0*/ T> foo(): T
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun </*0*/ T> foo2(): T
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
}

View File

@@ -0,0 +1,17 @@
// !LANGUAGE: +ExpectedTypeFromCast
class X<S> {
fun <T : S> foo(): T = TODO()
}
fun test(x: X<Number>) {
val <!UNUSED_VARIABLE!>y<!> = x.foo() as Int
}
fun <S, D: S> g() {
fun <T : S> foo(): T = TODO()
val <!UNUSED_VARIABLE!>y<!> = <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>foo<!>() as Int
val <!UNUSED_VARIABLE!>y2<!> = foo() as D
}

View File

@@ -0,0 +1,12 @@
package
public fun </*0*/ S, /*1*/ D : S> g(): kotlin.Unit
public fun test(/*0*/ x: X<kotlin.Number>): kotlin.Unit
public final class X</*0*/ S> {
public constructor X</*0*/ S>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun </*0*/ T : S> foo(): T
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}

View File

@@ -0,0 +1,58 @@
// !LANGUAGE: +ExpectedTypeFromCast
// !DIAGNOSTICS: -UNUSED_VARIABLE -DEBUG_INFO_LEAKING_THIS
// FILE: a/View.java
package a;
public class View {
}
// FILE: a/Test.java
package a;
public class Test {
public <T extends View> T findViewById(int id);
}
// FILE: 1.kt
package a
class X : View()
class Y<T> : View()
val xExplicit: X = Test().findViewById(0)
val xCast = Test().findViewById(0) as X
val xCastExplicitType = Test().findViewById<X>(0) as X
val xSafeCastExplicitType = Test().findViewById<X>(0) <!USELESS_CAST!>as? X<!>
val yExplicit: Y<String> = Test().findViewById(0)
val yCast = Test().findViewById(0) as Y<String>
class TestChild : Test() {
val xExplicit: X = findViewById(0)
val xCast = findViewById(0) as X
val yExplicit: Y<String> = findViewById(0)
val yCast = findViewById(0) as Y<String>
}
fun test(t: Test) {
val xExplicit: X = t.findViewById(0)
val xCast = t.findViewById(0) as X
val yExplicit: Y<String> = t.findViewById(0)
val yCast = t.findViewById(0) as Y<String>
}
fun test2(t: Test?) {
val xSafeCallSafeCast = t?.findViewById(0) as? X
val xSafeCallSafeCastExplicitType = t?.findViewById<X>(0) <!USELESS_CAST!>as? X<!>
val xSafeCallCast = t?.findViewById(0) as X
val xSafeCallCastExplicitType = t<!UNNECESSARY_SAFE_CALL!>?.<!>findViewById<X>(0) as X
}

View File

@@ -0,0 +1,53 @@
package
package a {
public val xCast: a.X
public val xCastExplicitType: a.X
public val xExplicit: a.X
public val xSafeCastExplicitType: a.X?
public val yCast: a.Y<kotlin.String>
public val yExplicit: a.Y<kotlin.String>
public fun test(/*0*/ t: a.Test): kotlin.Unit
public fun test2(/*0*/ t: a.Test?): kotlin.Unit
public open class Test {
public constructor Test()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open fun </*0*/ T : a.View!> findViewById(/*0*/ id: kotlin.Int): T!
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class TestChild : a.Test {
public constructor TestChild()
public final val xCast: a.X
public final val xExplicit: a.X
public final val yCast: a.Y<kotlin.String>
public final val yExplicit: a.Y<kotlin.String>
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun </*0*/ T : a.View!> findViewById(/*0*/ id: kotlin.Int): T!
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public open class View {
public constructor View()
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
}
public final class X : a.View {
public constructor X()
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
}
public final class Y</*0*/ T> : a.View {
public constructor Y</*0*/ T>()
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
}
}

View File

@@ -0,0 +1,34 @@
// !DIAGNOSTICS: -INVISIBLE_MEMBER -INVISIBLE_REFERENCE
// !API_VERSION: 1.2
// FILE: a.kt
<!JVM_PACKAGE_NAME_NOT_SUPPORTED_IN_MULTIFILE_CLASSES!>@file:JvmPackageName("a")<!>
@file:JvmMultifileClass
package a
fun a() {}
// FILE: b.kt
<!JVM_PACKAGE_NAME_CANNOT_BE_EMPTY!>@file:JvmPackageName("")<!>
package b
fun b() {}
// FILE: c.kt
<!JVM_PACKAGE_NAME_MUST_BE_VALID_NAME!>@file:JvmPackageName("invalid-fq-name")<!>
package c
fun c() {}
// FILE: d.kt
<!JVM_PACKAGE_NAME_NOT_SUPPORTED_IN_FILES_WITH_CLASSES!>@file:JvmPackageName("d")<!>
package d
class D
fun d() {}
// FILE: e.kt
@file:JvmPackageName(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>)
package e
fun e() {}
// FILE: f.kt
@file:JvmPackageName(<!EXPRESSION_EXPECTED_PACKAGE_FOUND!>f<!>)
package f
const val name = "f"

View File

@@ -0,0 +1,32 @@
package
package a {
public fun a(): kotlin.Unit
}
package b {
public fun b(): kotlin.Unit
}
package c {
public fun c(): kotlin.Unit
}
package d {
public fun d(): kotlin.Unit
public final class D {
public constructor D()
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
}
}
package e {
public fun e(): kotlin.Unit
}
package f {
public const val name: kotlin.String = "f"
}

View File

@@ -0,0 +1,88 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE
// !API_VERSION: 1.2
// FILE: test.kt
interface Base {
var x: String
}
open class Foo : Base {
override lateinit var x: String
private lateinit var y: String
var nonLateInit: Int = 1
fun ok() {
val b: Boolean = this::x.isInitialized
val otherInstance = Foo()
otherInstance::x.isInitialized
(this::x).isInitialized
(@Suppress("ALL") (this::x)).isInitialized
object {
fun local() {
class Local {
val xx = this@Foo::x.isInitialized
val yy = this@Foo::y.isInitialized
}
}
}
}
fun onLiteral() {
val p = this::x
p.<!LATEINIT_INTRINSIC_CALL_ON_NON_LITERAL!>isInitialized<!>
}
fun onNonLateinit() {
this::nonLateInit.<!LATEINIT_INTRINSIC_CALL_ON_NON_LATEINIT!>isInitialized<!>
}
inline fun inlineFun() {
this::x.<!LATEINIT_INTRINSIC_CALL_IN_INLINE_FUNCTION!>isInitialized<!>
object {
val z = this@Foo::x.isInitialized
}
}
inner class InnerSubclass : Foo() {
fun innerOk() {
// This is access to Foo.x declared lexically above
this@Foo::x.isInitialized
// This is access to InnerSubclass.x which is inherited from Foo.x
this::x.isInitialized
}
}
}
fun onNonAccessible() {
Foo()::x.<!LATEINIT_INTRINSIC_CALL_ON_NON_ACCESSIBLE_PROPERTY!>isInitialized<!>
}
fun onNonLateinit() {
Foo()::nonLateInit.<!LATEINIT_INTRINSIC_CALL_ON_NON_LATEINIT!>isInitialized<!>
}
object Unrelated {
fun onNonAccessible() {
Foo()::x.<!LATEINIT_INTRINSIC_CALL_ON_NON_ACCESSIBLE_PROPERTY!>isInitialized<!>
}
}
class FooImpl : Foo() {
fun onNonAccessible() {
this::x.<!LATEINIT_INTRINSIC_CALL_ON_NON_ACCESSIBLE_PROPERTY!>isInitialized<!>
}
}
// FILE: other.kt
class OtherFooImpl : Foo() {
fun onNonAccessible() {
this::x.<!LATEINIT_INTRINSIC_CALL_ON_NON_ACCESSIBLE_PROPERTY!>isInitialized<!>
}
}

View File

@@ -0,0 +1,78 @@
package
public fun onNonAccessible(): kotlin.Unit
public fun onNonLateinit(): kotlin.Unit
public interface Base {
public abstract var x: 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
}
public open class Foo : Base {
public constructor Foo()
public final var nonLateInit: kotlin.Int
public open override /*1*/ lateinit var x: kotlin.String
private final lateinit var y: 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 final inline fun inlineFun(): kotlin.Unit
public final fun ok(): kotlin.Unit
public final fun onLiteral(): kotlin.Unit
public final fun onNonLateinit(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final inner class InnerSubclass : Foo {
public constructor InnerSubclass()
public final override /*1*/ /*fake_override*/ var nonLateInit: kotlin.Int
public open override /*1*/ lateinit /*fake_override*/ var x: kotlin.String
invisible_fake final override /*1*/ lateinit /*fake_override*/ var y: 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 final inline override /*1*/ /*fake_override*/ fun inlineFun(): kotlin.Unit
public final fun innerOk(): kotlin.Unit
public final override /*1*/ /*fake_override*/ fun ok(): kotlin.Unit
public final override /*1*/ /*fake_override*/ fun onLiteral(): kotlin.Unit
public final override /*1*/ /*fake_override*/ fun onNonLateinit(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public final class FooImpl : Foo {
public constructor FooImpl()
public final override /*1*/ /*fake_override*/ var nonLateInit: kotlin.Int
public open override /*1*/ lateinit /*fake_override*/ var x: kotlin.String
invisible_fake final override /*1*/ lateinit /*fake_override*/ var y: 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 final inline override /*1*/ /*fake_override*/ fun inlineFun(): kotlin.Unit
public final override /*1*/ /*fake_override*/ fun ok(): kotlin.Unit
public final override /*1*/ /*fake_override*/ fun onLiteral(): kotlin.Unit
public final fun onNonAccessible(): kotlin.Unit
public final override /*1*/ /*fake_override*/ fun onNonLateinit(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class OtherFooImpl : Foo {
public constructor OtherFooImpl()
public final override /*1*/ /*fake_override*/ var nonLateInit: kotlin.Int
public open override /*1*/ lateinit /*fake_override*/ var x: kotlin.String
invisible_fake final override /*1*/ lateinit /*fake_override*/ var y: 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 final inline override /*1*/ /*fake_override*/ fun inlineFun(): kotlin.Unit
public final override /*1*/ /*fake_override*/ fun ok(): kotlin.Unit
public final override /*1*/ /*fake_override*/ fun onLiteral(): kotlin.Unit
public final fun onNonAccessible(): kotlin.Unit
public final override /*1*/ /*fake_override*/ fun onNonLateinit(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public object Unrelated {
private constructor Unrelated()
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 final fun onNonAccessible(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}

View File

@@ -0,0 +1,10 @@
OUT:
Buildfile: [TestData]/build.xml
build:
[kotlinc] Compiling [[TestData]/main.kt] => [[Temp]/test.jar]
BUILD SUCCESSFUL
Total time: [time]
Return code: 0

View File

@@ -0,0 +1,15 @@
<project name="Ant Task Test" default="build">
<taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
<target name="build">
<kotlinc src="${test.data}/main.kt" output="${temp}/test.jar" nowarn="true">
<classpath>
<file file="${kotlin.stdlib.jre7.jar}"/>
<file file="${kotlin.stdlib.jre8.jar}"/>
<file file="${kotlin.stdlib.jdk7.jar}"/>
<file file="${kotlin.stdlib.jdk8.jar}"/>
</classpath>
<compilerarg line="-jvm-target 1.8"/>
</kotlinc>
</target>
</project>

View File

@@ -0,0 +1,15 @@
import java.util.stream.Stream
import kotlin.streams.*
// kotlin-stdlib-jdk7
fun testUse(c: AutoCloseable) = c.use {}
// kotlin-stdlib-jdk8
fun testGet(c: MatchGroupCollection) = c.get("")
fun testGetOrDefault(c: Map<out Number, Any>) = c.getOrDefault(42, "")
fun testRemove(c: MutableMap<out Number, Any>) = c.remove(42, "")
fun testAsSequence(c: Stream<String>) = c.asSequence()

View File

@@ -0,0 +1 @@
OK

View File

@@ -0,0 +1,4 @@
module usage {
requires kotlin.stdlib;
requires kotlin.reflect;
}

View File

@@ -0,0 +1,11 @@
import kotlin.reflect.*
import kotlin.reflect.jvm.*
import kotlin.reflect.full.*
class Test<T> {
fun test() {
Test::class.allSupertypes
Test::class.createType(listOf(KTypeProjection.STAR))
this::test.javaMethod
}
}

View File

@@ -0,0 +1 @@
OK

View File

@@ -0,0 +1,15 @@
import java.util.stream.Stream
import kotlin.streams.*
// kotlin-stdlib-jdk7
fun testUse(c: AutoCloseable) = c.use {}
// kotlin-stdlib-jdk8
fun testGet(c: MatchGroupCollection) = c.get("")
fun testGetOrDefault(c: Map<out Number, Any>) = c.getOrDefault(42, "")
fun testRemove(c: MutableMap<out Number, Any>) = c.remove(42, "")
fun testAsSequence(c: Stream<String>) = c.asSequence()

View File

@@ -0,0 +1,5 @@
module usage {
requires kotlin.stdlib;
requires kotlin.stdlib.jdk7;
requires kotlin.stdlib.jdk8;
}

View File

@@ -0,0 +1,5 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@file:JvmPackageName("j")
package bar
fun file0() {}

View File

@@ -0,0 +1,6 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@file:JvmName("JJ")
@file:JvmPackageName("jj")
package bar
fun jj() {}

View File

@@ -0,0 +1,3 @@
package foo
fun file1() {}

View File

@@ -0,0 +1,5 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@file:JvmPackageName("jjj")
package foo
fun file2() {}

View File

@@ -0,0 +1,5 @@
@file:JvmMultifileClass
@file:JvmName("MultiFoo")
package foo
fun multiFile1() {}

View File

@@ -0,0 +1,7 @@
bar
j/BarAsJKt
jj/JJ
foo
foo/MultiFoo__FooMultiFileKt (foo/MultiFoo)
foo/FooKt
jjj/FooAsJJJKt

View File

@@ -0,0 +1,3 @@
package foo
fun file1() {}

View File

@@ -0,0 +1,5 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@file:JvmPackageName("j")
package foo
fun file2() {}

View File

@@ -0,0 +1,2 @@
foo
foo/FooKt

View File

@@ -0,0 +1,5 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@file:JvmPackageName("foo.jvm")
package foo
fun foo1() {}

View File

@@ -0,0 +1,5 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@file:JvmPackageName("foo.jvm")
package foo
fun foo2() {}

View File

@@ -0,0 +1,5 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@file:JvmPackageName("foo.jvm")
package foo
fun foo3() {}

View File

@@ -0,0 +1,4 @@
foo
foo/jvm/Foo1Kt
foo/jvm/Foo2Kt
foo/jvm/Foo3Kt

View File

@@ -5,7 +5,7 @@ Output:
-- JVM --
Exit code: COMPILATION_ERROR
Output:
compiler/testData/multiplatform/missingOverload/common.kt:7:1: error: expected function 'g' has no actual in module
compiler/testData/multiplatform/missingOverload/common.kt:7:1: error: expected function 'g' has no actual declaration in module
The following declaration is incompatible because parameter types are different:
public actual fun g(a: Any): Unit

View File

@@ -33,6 +33,10 @@ public abstract class AbstractAntTaskTest extends KotlinIntegrationTestBase {
"-Dkotlin.lib=" + KotlinIntegrationTestBase.getCompilerLib(),
"-Dkotlin.runtime.jar=" + ForTestCompileRuntime.runtimeJarForTests().getAbsolutePath(),
"-Dkotlin.reflect.jar=" + ForTestCompileRuntime.reflectJarForTests().getAbsolutePath(),
"-Dkotlin.stdlib.jre7.jar=" + new File("dist/kotlinc/lib/kotlin-stdlib-jre7.jar").getAbsolutePath(),
"-Dkotlin.stdlib.jre8.jar=" + new File("dist/kotlinc/lib/kotlin-stdlib-jre8.jar").getAbsolutePath(),
"-Dkotlin.stdlib.jdk7.jar=" + new File("dist/kotlinc/lib/kotlin-stdlib-jdk7.jar").getAbsolutePath(),
"-Dkotlin.stdlib.jdk8.jar=" + new File("dist/kotlinc/lib/kotlin-stdlib-jdk8.jar").getAbsolutePath(),
"-Dtest.data=" + testDataDir,
"-Dtemp=" + tmpdir,
"-f", "build.xml"

View File

@@ -10407,6 +10407,33 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
}
}
@TestMetadata("compiler/testData/codegen/box/jvmPackageName")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmPackageName extends AbstractIrBlackBoxCodegenTest {
public void testAllFilesPresentInJvmPackageName() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("rootPackage.kt")
public void testRootPackage() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/rootPackage.kt");
doTest(fileName);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/simple.kt");
doTest(fileName);
}
@TestMetadata("withJvmName.kt")
public void testWithJvmName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/withJvmName.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/jvmStatic")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -11840,6 +11867,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
doTest(fileName);
}
@TestMetadata("classCompanion.kt")
public void testClassCompanion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/classCompanion.kt");
doTest(fileName);
}
@TestMetadata("flist.kt")
public void testFlist() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/flist.kt");
@@ -11858,6 +11891,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
doTest(fileName);
}
@TestMetadata("interfaceCompanion.kt")
public void testInterfaceCompanion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/interfaceCompanion.kt");
doTest(fileName);
}
@TestMetadata("kt1047.kt")
public void testKt1047() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/kt1047.kt");
@@ -11996,6 +12035,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
doTest(fileName);
}
@TestMetadata("object.kt")
public void testObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/object.kt");
doTest(fileName);
}
@TestMetadata("objectExtendsInnerAndReferencesOuterMember.kt")
public void testObjectExtendsInnerAndReferencesOuterMember() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/objectExtendsInnerAndReferencesOuterMember.kt");
@@ -13612,6 +13657,39 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
doTest(fileName);
}
@TestMetadata("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class IsInitializedAndDeinitialize extends AbstractIrBlackBoxCodegenTest {
public void testAllFilesPresentInIsInitializedAndDeinitialize() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("innerSubclass.kt")
public void testInnerSubclass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/innerSubclass.kt");
doTest(fileName);
}
@TestMetadata("sideEffects.kt")
public void testSideEffects() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/sideEffects.kt");
doTest(fileName);
}
@TestMetadata("simpleIsInitialized.kt")
public void testSimpleIsInitialized() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/simpleIsInitialized.kt");
doTest(fileName);
}
@TestMetadata("topLevelProperty.kt")
public void testTopLevelProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/topLevelProperty.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/properties/lateinit/local")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -17510,6 +17588,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
doTest(fileName);
}
@TestMetadata("expectedTypeFromCast.kt")
public void testExpectedTypeFromCast() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reified/expectedTypeFromCast.kt");
doTest(fileName);
}
@TestMetadata("filterIsInstance.kt")
public void testFilterIsInstance() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reified/filterIsInstance.kt");

Some files were not shown because too many files have changed in this diff Show More