KT-37861 'this' is uninitialized in constructor default parameters
This commit is contained in:
@@ -1207,6 +1207,10 @@ public class FunctionCodegen {
|
||||
@NotNull MemberCodegen<?> parentCodegen,
|
||||
@NotNull Method defaultMethod
|
||||
) {
|
||||
if (methodContext instanceof ConstructorContext) {
|
||||
((ConstructorContext) methodContext).setThisInitialized(false);
|
||||
}
|
||||
|
||||
GenerationState state = parentCodegen.state;
|
||||
JvmMethodSignature signature = state.getTypeMapper().mapSignatureWithGeneric(functionDescriptor, methodContext.getContextKind());
|
||||
|
||||
|
||||
+13
@@ -854,6 +854,19 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
checkSamCall(call);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitParameter(@NotNull KtParameter parameter) {
|
||||
PsiElement parent = parameter.getParent(); // KtParameterList
|
||||
if (parent != null && parent.getParent() instanceof KtConstructor<?>) {
|
||||
KtExpression defaultValue = parameter.getDefaultValue();
|
||||
if (defaultValue != null) {
|
||||
withinUninitializedClass(defaultValue, () -> defaultValue.accept(this));
|
||||
}
|
||||
} else {
|
||||
super.visitParameter(parameter);
|
||||
}
|
||||
}
|
||||
|
||||
private void withinUninitializedClass(@NotNull KtElement element, @NotNull Runnable operation) {
|
||||
ClassDescriptor currentClass = peekFromStack(classStack);
|
||||
assert currentClass != null : element.getClass().getSimpleName() + " should be inside a class: " + element.getText();
|
||||
|
||||
Reference in New Issue
Block a user