From 8d8bda6b88d73f71e68ea1008b7965295a0e3bc5 Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Wed, 24 Jan 2024 02:01:45 -0500 Subject: [PATCH] move adapt parameter logic from AnnotatedTypeFactory#constructorFromUse to here --- .../inference/InferenceAnnotatedTypeFactory.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/checkers/inference/InferenceAnnotatedTypeFactory.java b/src/checkers/inference/InferenceAnnotatedTypeFactory.java index 53d689b9..61bb209e 100644 --- a/src/checkers/inference/InferenceAnnotatedTypeFactory.java +++ b/src/checkers/inference/InferenceAnnotatedTypeFactory.java @@ -394,7 +394,19 @@ public ParameterizedExecutableType constructorFromUse(final NewClassTree newClas addComputedTypeAnnotations(newClassTree, constructorReturnType); final AnnotatedExecutableType constructorType = AnnotatedTypes.asMemberOf(types, this, constructorReturnType, constructorElem); - + // Take adapt parameter logic from AnnotatedTypeFactory#constructorFromUse to + // InferenceAnnotatedTypeFactory#constructorFromUse + // Store varargType before calling setParameterTypes, otherwise we may lose the + // varargType as it is the last element of the original parameterTypes. + // AnnotatedTypes.asMemberOf handles vararg type properly, so we do not need to compute + // vararg type again. + constructorType.computeVarargType(); + // Adapt parameters, which makes parameters and arguments be the same size for later + // checking. The vararg type of con has been already computed and stored when calling + // typeVarSubstitutor.substitute. + List parameters = + AnnotatedTypes.adaptParameters(this, constructorType, newClassTree.getArguments()); + constructorType.setParameterTypes(parameters); if (viewpointAdapter != null) { viewpointAdapter.viewpointAdaptConstructor(constructorReturnType, constructorElem, constructorType); }