[FIR] Avoid AST loading in KtPrimaryConstructor.toFirConstructor

- `getConstructorKeyword` forces an AST load due to a child search. In
  most cases, we don't need to check the constructor keyword in primary
  constructors at all (e.g. `class ABC()` with an implicit primary
  constructor). The keyword check is only needed when there are primary
  constructor modifiers (e.g. `class ABC constructor()`).

Thanks to Dima Gridin for the suggested fix.

^KT-61635 fixed
This commit is contained in:
Marco Pennekamp
2023-08-31 22:09:55 +02:00
parent 761221904c
commit 6b0333d74c
@@ -1083,9 +1083,9 @@ open class PsiRawFirBuilder(
isFromSealedClass = owner.hasModifier(SEALED_KEYWORD) && explicitVisibility !== Visibilities.Private
isFromEnumClass = owner.hasModifier(ENUM_KEYWORD)
}
val hasConstructorKeyword = this@toFirConstructor?.getConstructorKeyword() != null
val builder = when {
this?.modifierList != null && !hasConstructorKeyword -> createErrorConstructorBuilder(ConeMissingConstructorKeyword)
this?.modifierList != null && getConstructorKeyword() == null -> createErrorConstructorBuilder(ConeMissingConstructorKeyword)
isErrorConstructor -> createErrorConstructorBuilder(ConeNoConstructorError)
else -> FirPrimaryConstructorBuilder()
}