The first change here is swapping the isCompatibility and hasJvmDefault
checks. Otherwise behavior could be different depending on -Xjvm-default
mode even for non-JvmDefault declarations, which makes little sense.
Another change is avoiding generating $default stubs for fake overrides
in interfaces, which replicates the behavior of the current backend.
(Note that this change also fixes the first problem on the newly added
tests, but the first change seems useful anyway.)
Not sure if this affects real code, but this could happen in erroneous
cases such as in the subsequent commit, where it was a bit weird to see
this suffix without any supercalls involved.
This only reproduced when compiling (technically incorrect) code in the
standard library, where private functions monitorEnter/monitorExit are
accessed from another file, and their names with suffixes are not
recognized as intrinsics which should be replaced by
monitorenter/monitorexit JVM bytecode instructions.
This would help for example in debugging the issue fixed in the previous
commit.
The only problem by now where this lowering tried to add accessors to
foreign files was reproduced for interfaces inheriting from Cloneable.
There, we generate a DefaultImpls bridge that calls protected method
`clone` from java.lang.Cloneable.DefaultImpls. This makes no sense, but
the old backend behaves the same. Instead of generating accessor for it
in JVM IR, we now see all DefaultImpls bridges as public as a
workaround. (The fact that assertion no longer fails here is checked
e.g. by box/reflection/mapping/methodsFromObject.kt.)
SyntheticAccessorLowering was initially implemented under the assumption
that any access to an invisible declaration will cause an accessor to be
generated _in the same file_. Moreover, it's declared in the group of
phases that are performed by file.
But this assumption is incorrect for constructors which need to be
hidden (those which take parameters of inline class types), since such
constructor is public and can be called from anywhere. In this case,
SyntheticAccessorLowering actually generated a new accessor for the
hidden constructor for each (!) source file where that constructor is
called, which led to ClassFormatError because of the class file having
multiple methods with the same signature. The internal `functionMap`
cache didn't help because it's not shared among phase instances for
different files (well, it helped to generate not more than one accessor
per usage-file).
In this change, we use the global cache, stored in JvmBackendContext,
for accessors to hidden constructors. Note that after this change, calls
to hidden constructors are always transformed to the corresponding
accessor in SyntheticAccessorLowering right away, but that accessor
might be orphaned for a while (not declared in any parent's
declarations). Only when SyntheticAccessorLowering encounters the
original constructor which needs to be hidden, it adds the accessor
beside it.
The test is sensitive to the file order, so both variants are added.
See KT-35849.
1. When expected lambda return type is a type parameter, don't generate
introduce implicit casts (even if the corresponding type parameter has
an upper bound that would otherwise require such cast).
2. Do not generate implicit null check for lambda return value of
@EnhancedNullability type.
Rename fictitiousFunctionSymbols -> syntheticFunctionalInterfaceSymbols
Support suspend function interfaces
Add supertypes for KFunction / KSuspendFunction
Currently FirThisReceiverExpression of instance methods are translated
to references of the class' thisReceiver,
not the method's dispatch receiver,
which causes problems with IrFrameMap::typeOf,
as the class' thisReceiver is not in the typeMap.
This commit translates non-qualified "this" references of
instance methods to references of the methods' dispatch receiver.
In the existing implementation, the information that a library function
parameter has a default value is lost during Fir2Ir translation,
and thus later on,
calls to such functions are not converted to the corresponding stubs.
Test cases such as kt5844, which calls kotlin.test.assertEquals,
fail with messages like "java.lang.IllegalArgumentException:
Null argument in ExpressionCodegen for parameter VALUE_PARAMETER
name:message index:2 type:kotlin.String?",
due to nonnull checks in ExpressionCodegen.visitFunctionAccess
(ExpressionCodegen.kt:421)
Functions defined in the code to be compiled don't have this problem,
only those from deserializing jars.
This commit sets default values in IrValueParameterImpl
for such parameters during Fir2Ir translation.
Now kt5844 passes the nonnull check in
ExpressionCodegen.visitFunctionAccess but still fails in a later stage
(java.lang.ClassNotFoundException: kotlin.internal.ir.Intrinsic).
Since 1.3.70 an iOS simulator test task is created by the MPP Gradle
plugin out of the box. So we stop creating such a task manually in
the shared library project template.
Issue #KT-35560 Fixed.
'base' plugin is enough in this case, given that a couple of tasks is registered and configured manually.
Fix kotlin-reflect dependency to be a project dependency.
The switch `includeStdlibJsIr` now affects which artifact is published:
the one with IR or the one without. Previously it affected
whether or not IR was bundled into the artifact "with IR".
Local functions raised in LocalDeclarationLowering continue to refer to
type parameters that are no longer visible to them.
This commit only adds new type parameters to their declarations, which
makes JVM accept those declarations. The generated IR is still
semantically incorrect (needs further fix), but code generation seems
to proceed nevertheless.
Whenever we want the default 0/null value for a type we need to
check if it is a non-nullable inline class type and produce
the right value for the underlying type.