[FIR] Introduce FirDeclarationStatus.hasStableParameterNames

This flag is true by default but is set to false for

- Java methods and constructors
- interface delegation methods that delegate to Java

The NAMED_ARGUMENTS_NOT_ALLOWED logic is mostly refactored to use the
new flag though some custom logic remains for determining the correct
message and to work around a corner case with fake overrides.

The flag is (de)serialized from/to metadata. For backward compatibility
with K1, delegated methods to Java types are deserialized as stable.

^KT-40480 Fixed
This commit is contained in:
Kirill Rakhman
2023-02-03 12:08:17 +01:00
committed by Space Team
parent 152e63b198
commit 314784f435
29 changed files with 156 additions and 51 deletions
@@ -433,8 +433,9 @@ class FirElementSerializer private constructor(
simpleFunction?.isExternal == true,
simpleFunction?.isSuspend == true,
simpleFunction?.isExpect == true,
true // TODO: supply 'hasStableParameterNames' flag for metadata
shouldSetStableParameterNames(simpleFunction),
)
if (flags != builder.flags) {
builder.flags = flags
}
@@ -507,6 +508,15 @@ class FirElementSerializer private constructor(
return builder
}
private fun shouldSetStableParameterNames(simpleFunction: FirSimpleFunction?): Boolean {
return when {
simpleFunction?.hasStableParameterNames == true -> true
// for backward compatibility with K1, remove this line to fix KT-4758
simpleFunction?.origin == FirDeclarationOrigin.Delegated -> true
else -> false
}
}
private fun typeAliasProto(typeAlias: FirTypeAlias): ProtoBuf.TypeAlias.Builder? = whileAnalysing(session, typeAlias) {
if (!extension.shouldSerializeTypeAlias(typeAlias)) return null
@@ -570,7 +580,7 @@ class FirElementSerializer private constructor(
constructor.nonSourceAnnotations(session).isNotEmpty(),
ProtoEnumFlags.visibility(normalizeVisibility(constructor)),
!constructor.isPrimary,
true // TODO: supply 'hasStableParameterNames' flag for metadata
constructor.hasStableParameterNames,
)
if (flags != builder.flags) {
builder.flags = flags