Commit Graph

150 Commits

Author SHA1 Message Date
Denis.Zharkov 360d67410d FIR: Fix overridability rule for Java declarations with different return type kinds
See the class at org/jmock/Expectations
public <T> T with(Matcher<T> matcher);
public boolean with(Matcher<Boolean> matcher);

When we extending such class it we start assuming
that fake generic override overrides both of the overridden that is wrong
from POV of Java and it fails at FIR ultimate build

NB: It's hard to write a test because such Expectation-like
class is impossible to write in pure Java
2021-11-02 19:08:28 +03:00
Mikhael Bogdanov afc149d460 JvmDefault. Allow non default inheritance with special flag
#KT-47000
2021-11-01 13:30:57 +01:00
Ilya Chernikov 600529fe21 temp: fix testdata until diagnostic reporting is fixed properly
currently some old backend reporting schemes are used in IR backend that
rely on the PSI alement passing. This conflicts with updated generic
diagnostic infrastructure that is shared between FIR and IR backends.
As soon as such places will be abstracted out and the IR will be
completely switched to the new diagnostic infrastructure, this and
similar changes could be reverted.
2021-10-27 22:17:42 +02:00
Alexander Udalov 4f29c113b7 Remove KotlinCompilerVersion.IS_PRE_RELEASE
Now, milestones of major Kotlin releases (e.g. 1.6.0-M1) will NOT
generate prerelease binaries anymore.

The reason for that is it's proven to be quite a complicated process to
turn on IR_PRE_RELEASE after the release is branched, perform double
bootstrap and fix tests, and then do it again in reverse just before
release. With the new release cadence, we don't have that much time to
do it and verify that everything works as intended.

Note that this only removes the "global" prerelease flag. Compiler will
still generate prerelease binaries if a non-stable language version is
used. For example, Kotlin 1.6.0-M1 with `-language-version 1.7` will
generate prerelease binaries.
2021-08-24 16:23:42 +02:00
Mikhael Bogdanov 390eda1b9d Fix CompileKotlinAgainstCustomBinariesTest tests 2021-07-29 19:45:54 +02:00
Dmitriy Novozhilov f1cef0fc95 Update testdata 2021-04-03 16:52:05 +03:00
Ilya Chernikov 20fdad87ec FIR: support direct use of typealias with friend-paths
also fixes one IC test
2021-03-24 21:24:19 +01:00
Alexander Udalov 247efb220c Do not require backing fields for extension properties
This has no effect on correct code because extension properties cannot
have a backing field anyway and that is checked separately. But this
function is used in psi2ir to determine whether or not to create a
backing field for a property, and in case the code where the property is
declared is unreachable like in KT-44496 and has no explicit getter or
setter, it would previously return true for extension properties, which
on JVM would result in an actual field in the class file, which made no
sense.

After this change, the compiler will actually crash with an exception in
the IR validaton step because the symbol for the field is unbound. That
is a bit better than proceeding to generate potentially invalid
bytecode, but of course a proper fix would be to report an error in the
frontend.

 #KT-44496
2021-03-09 20:50:39 +01:00
Mikhael Bogdanov 4d51d71699 Fix EXPLICIT_OVERRIDE_REQUIRED_IN_MIXED_MODE message 2021-03-08 17:52:52 +00:00
Mikhael Bogdanov 3568eba1b2 Use actual implementation instead of inherited one in -Xjvm-default diagnostics 2021-03-08 17:52:52 +00:00
Mikhael Bogdanov 71c134e54f Fix checker for -Xjvm-defaults 2021-03-08 17:52:51 +00:00
Pavel Kirpichenkov c68a4bdc0f [MPP] Consider expect-actual inline/value classes interchangeable
^KT-44926 Fixed
2021-03-01 19:25:31 +03:00
Pavel Kirpichenkov c8c44da061 Add test for KT-44926 2021-03-01 19:25:29 +03:00
Alexander Udalov d300e05be9 Remove obsolete code in inliner for experimental coroutines 2021-02-23 12:45:41 +01:00
Alexander Udalov 8c95b78346 Update JVM metadata version to 1.5.0
Improve the test which checks that we use correct metadata version if
`-language-version` is passed by checking all supported language
versions.

The change in libraries/reflect/build.gradle.kts is needed because
kotlinx-metadata-jvm of version 0.1.0 is based on pre-1.4 Kotlin, which
doesn't support the new module file metadata generated with metadata
version 1.4 and later, and module files need to be readable there to be
able to transform them for the shadow plugin.

Similarly override dependency on kotlinx-metadata-jvm in the
binary-compatibility-validator module.
2021-02-18 12:42:23 +01:00
Dmitriy Novozhilov f3a8fcaea6 [FE] Make constructors of sealed classes protected instead of internal 2021-02-12 13:36:38 +03:00
Pavel Kirpichenkov 2a46da906c Provide additional information about missing supertypes
Add -X flag to report extra compiler diagnostics which migth break compatibility.
Use the flag to unconditionally check constructors without fear of
prematurely evaluating lazy supertypes.

KT-19234
KT-42404
KT-44583
2021-02-08 18:47:30 +03:00
Pavel Kirpichenkov 8f675fe757 Split combined test into two to avoid flaky behaviour
Prevent simultaneous access to the library directory
2021-02-01 15:09:13 +03:00
Alexander Udalov d022bb0248 Switch default JVM target to 1.8
#KT-29405 Fixed
2021-02-01 11:54:04 +01:00
Dmitriy Novozhilov f3393eae1b [Test] Update testdata of CompileKotlinAgainstCustomBinariesTest 2021-01-28 13:19:26 +03:00
Pavel Kirpichenkov 5c28762c02 Fix check for local classes in approximating string table
Take local/anonymous classes and their inner classes into account.
Simplify approximation: use first available super classifier instead
of first super class. This approximation should only happen for
private declarations that were not previously approximated by frontend.
So basically the only requirement for the approximated types is to be
denotable. Note that this only works if the types are not used later.
JVM uses a different string table implementatin as it needs exact
types of private members for reflection.

^KT-20996 Fixed
2021-01-20 11:05:53 +03:00
Pavel Kirpichenkov 2f3f75b512 Fix local anonymous class name error in K2MetadataCompiler
Extract the logic of approximating to denotable class supertype
from JS/KLIB and use it in metadata compiler.

^KT-20996 In Progress
2021-01-20 11:05:53 +03:00
pyos f618763250 FIR: implement -Xfriend-paths 2021-01-12 10:33:45 +03:00
Alexander Udalov eef06cded3 JVM IR: output stable ABI binaries by default
#KT-43592 Fixed
2020-12-20 23:14:54 +01:00
Dmitriy Novozhilov b6bd7c48f4 [FE] Rename FreedomForSealedClasses feature with more meaningful name 2020-12-09 22:54:38 +03:00
Dmitriy Novozhilov 57a081c399 [FE] Prohibit inheritance of sealed classes in different module
KT-20423
2020-12-09 22:54:34 +03:00
Dmitriy Novozhilov c0a1aecf9b [FE] Add test for compiling against library with kotlin sealed classes and interfaces
#KT-20423
#KT-13495
2020-12-09 22:54:30 +03:00
Ilmir Usmanov c22071566e IC mangling: Use old mangling scheme when LV is 1.3
Add integration test to check, that nothing is broken with LV 1.3.
2020-11-19 17:39:34 +01:00
Mikhael Bogdanov 39cde978d0 Minor. Rename test folder 2020-10-06 07:14:39 +02:00
Mikhael Bogdanov b27955d268 Wrong specialization diagnostic is reported on java default inheritance 2020-10-05 20:09:21 +02:00
Mikhail Bogdanov 125c72cb8d New default checks for mixed hierarchies
Old and new schemes
2020-07-24 12:10:04 +02:00
Mikhail Zarechenskiy 6b81cc8b77 Update test data as stdlib now isn't pre-release 2020-06-30 22:59:23 +03:00
pyos 1fe7ef6521 JVM: separate the two kinds of source mappers
* a writing source mapper has `mapLineNumber(line, file, class)` that
   inserts a new SMAP entry and returns a fake line number from it;
 * a copying source mapper has `mapLineNumber(line)` that uses an
   existing SMAP to resolve the line number and call the former method
   on a different source mapper;
 * those two types are disjoint.
2020-05-19 18:33:27 +02:00
Alexander Udalov a0400f59c2 Add -Xskip-prerelease-check compiler argument
#KT-38070 Fixed
2020-05-07 13:24:26 +02:00
Kevin Bierhoff 7448761dfd only stub default constructor when compiling against .java source files 2020-04-07 17:48:39 +02:00
Mikhail Zarechenskiy 8fdc39ecbc Update test data due to using stdlib with a pre_release flag
The problem here is that we have separate bootstrap compiler and
 artifacts (stdlib, for example) that are used in tests and implicitly
 participate in them.

 For example, this test started to fail when bootstrap compiler was
 advanced to a version where pre_release flag is enabled. As a result,
 dependent stdlib become pre_release as well and now we have additional
 error about `Unit` type
2020-03-10 17:22:26 +03:00
Mikhail Zarechenskiy d169435300 Fix construction of Mock classes in case of generic inner types
This fixes testMissingDependencyConflictingLibraries for NI and also
 fixes changed test for OI as well
2020-02-20 12:34:35 +03:00
Alexander Udalov c08c3d4d9b Update JVM metadata version to 1.4.0 2020-02-06 17:22:02 +01:00
Pavel Kirpichenkov 87e0186334 Cleanup test checking legacy inline suspend
Move expected library compilation output to file.
^KT-36240 Fixed
2020-02-05 19:34:59 +03:00
Alexander Udalov 5e7343624b Update test data of wrongInlineTarget to 1.4 2020-02-05 13:09:53 +01:00
Pavel Kirpichenkov 5a04b7935e Add workaround for obsolete inline suspend integration test
Restore test data dropped in 7abd87d5, add specific output check
KT-36240
2020-01-29 21:41:07 +03:00
Pavel Kirpichenkov 913ed71863 Update error about unsupported language and API versions
Set first supported version to 1.3
Add property for oldest depecated language version in order to control unsupported ones
Report error on attempts to manually disable language feature from unsupported versions
Update test data, drop compatibility tests for features from unsupported versions

KT-36146 In progress
2020-01-29 21:40:44 +03:00
Alexander Udalov 953b461c53 Add new compiler errors and flags when JVM compiles against JVM IR
From now on, the old JVM backend will report an error by default when
compiling against class files produced by the JVM IR backend. This is
needed because we're not yet sure that the ABI generated by JVM IR is
fully correct and do not want to land in a 2-dimensional compatibility
situation where we'll need to consider twice more scenarios when
introducing any breaking change in the language. This is generally OK
since the JVM IR backend is still going to be experimental in 1.4.

However, for purposes of users which _do_ need to compile something with
the old backend against JVM IR, we provide two new compiler flags:
* -Xallow-jvm-ir-dependencies -- allows to suppress the error when
  compiling with the old backend against JVM IR.
* -Xir-binary-with-stable-api -- allows to mark the generated binaries
  as stable, when compiling anything with JVM IR, so that dependent
  modules will compile even with the old backend automatically. In this
  case, the author usually does not care for the generated ABI, or s/he
  ensures that it's consistent with the one expected by the old compiler
  with some external tools.

Internally, this is implemented by storing two new flags in
kotlin.Metadata: one tells if the class file was compiled with the JVM
IR, and another tells if the class file is stable (in case it's compiled
with JVM IR). Implementation is similar to the diagnostic reported by
the pre-release dependency checker.
2020-01-29 17:20:41 +01:00
pyos e54ef3bdb8 PSI2IR: ignore enum annotation arguments of error type
Similar to references to error type, this may happen if library A uses
an entity from library B annotated with an annotation from C, but A is
compiled without C on the classpath.
2019-12-26 10:10:29 +03:00
Ilmir Usmanov a1448ebb37 JVM_IR: Support crossinline suspend lambdas
The main idea is the following: since we need to generate
(fake)continuations before inlining, we move IrClasses of suspend
lambdas and continuation classes of named functions into the functions.
Thus, it allows the codegen to generate them prior to inlining and
the inliner will happily transform them for us.
Because of that, lowerings which transform call-site function are likely
to change reference to lowered suspend lambdas or functions.
Hence, do not rely on references to lowered suspend lambdas or
functions, instead, rely on attributes.

Do not generate continuation for inline suspend lambdas.
Previously, inline suspend lambdas were treated like suspend functions,
thus we generated continuations for them. Now we just do not treat them
as suspend functions or lambdas during AddContinuationLowering.
We should add continuation parameter to them, however.

Do not generate secondary constructor for suspend lambdas, otherwise,
the inliner is unable to transform them (it requires only one
constructor to be present).

Generate continuation classes for suspend functions as first statement
inside the function.
This enables suspend functions in local object inside inline functions.
Since we already have attributes inside suspend named functions, we
just reuse them to generate continuation class names. This allows us
to close the gap between code generated by old back-end and the new
one.

If a suspend named function captures crossinline lambda, we should
generate a template for inliner: a copy of the function without
state-machine and a continuation constructor call. The call is needed
so the inliner transforms the continuation as well.

Refactor CoroutineTransformerMethodVisitor, so it no longer depends on
PSI.
2019-12-23 18:03:40 +01:00
Pavel Kirpichenkov 55b3637f03 Fix case of inner object usage in missing supertypes checker
FakeCallableDescriptorForObject instance, which is not ConstructorDescriptor,
is checked with call checkers when object's contents are being used.
Checker of missing supertypes should not be run against this fake descriptor.
Object's members belong to separate member scope, so their resolution doesn't
force containing class' supertypes evaluation. I.e. object's methods
may work fine even if some supertypes of containing class are missing.
2019-11-25 10:57:52 +03:00
Pavel Kirpichenkov 8c52bb4212 Add frontend checks for missing dependency supertypes
Call checker and declaration checker are used in order to preserve backward compatibility.
Attempt to use classifier usage checker was not good enouth,
since not all errors found with it would actually be reported before.
For example types and constructor calls don't cause supertypes to resolve,
so missing supertypes would not lead to errors in case they are the only use of class name.

Updated tests failing due to missing Java dependencies in superclasses.
2019-11-18 12:06:41 +03:00
Mikhail Glukhikh 91a58fffb8 Add CLI test for K/javac project with non-transitive dependency, KT-33932 2019-10-18 12:29:05 +03:00
Alexander Udalov 0c939d2f86 Use correct class file version when copying anonymous objects in inliner
Generally, using state.classFileVersion would be enough because we
report an error when inlining bytecode into a class file with a lower
target version (see INLINE_FROM_HIGHER_PLATFORM). However, we take maxOf
with the original version of the class file, _just in case_ the user has
suppressed this error (for example, to workaround some other corner case
in the compiler).

 #KT-30744 Fixed
2019-10-08 13:44:40 +02:00
Alexander Udalov 59186b2617 Psi2ir: ignore unresolved class literals in annotations
Similarly to 38536638, skip annotation arguments that reference classes
which are not found in our compilation classpath.

This fix is especially needed because of the way _nested_ classes are
currently referenced in annotations. Since we don't generate all needed
InnerClasses attributes yet (KT-27936), we can't unambiguously resolve a
reference to a nested class in annotation arguments. This leads to an
ErrorValue loaded in the annotation descriptor. The old backend doesn't
care, since it doesn't look at that annotation or its arguments, but
psi2ir tries to convert all annotation arguments and it crashed with CCE
here, trying to cast IrErrorType to IrSimpleType.
2019-09-18 14:05:28 +02:00