Skip to content

Commit

Permalink
Fix an issue with resolved type parameters for function expressions (#…
Browse files Browse the repository at this point in the history
…927)

* Improve compiled state integrity test failure messages

* Clean up GenericTypeWithXArguments

* Add additional methods to TestTypeInferenceObserver

* Fix issue with resolved type parameters for function expressions
  • Loading branch information
kevin-m-knight-gs authored Jan 30, 2025
1 parent 4c41d1b commit e5617af
Show file tree
Hide file tree
Showing 14 changed files with 694 additions and 565 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public TypeInferenceObserver tryingRegistration(org.finos.legend.pure.m3.coreins
GenericType.print(this.appendable, templateGenType, this.processorState.getProcessorSupport());
print(" <-> ");
GenericType.print(this.appendable, genericType, this.processorState.getProcessorSupport());
print(" in ").print(typeInferenceContext.getId()).print("/").print(targetGenericsContext.getId()).print(" ");
print(" in ").print(typeInferenceContext.getId()).print("/").print(targetGenericsContext.getId());
return printNewline();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import org.eclipse.collections.api.factory.Stacks;
import org.eclipse.collections.api.stack.MutableStack;
import org.finos.legend.pure.m3.compiler.postprocessing.ProcessorState;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.Function;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.TypeParameter;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification;
import org.finos.legend.pure.m3.navigation.ProcessorSupport;
import org.finos.legend.pure.m4.coreinstance.CoreInstance;
Expand Down Expand Up @@ -150,6 +154,13 @@ public TypeInferenceObserver register(CoreInstance templateGenType, CoreInstance
return this;
}

@Override
public TypeInferenceObserver tryingRegistration(GenericType templateGenType, GenericType genericType, TypeInferenceContext typeInferenceContext, TypeInferenceContext targetGenericsContext)
{
activeObserver().tryingRegistration(templateGenType, genericType, typeInferenceContext, targetGenericsContext);
return this;
}

@Override
public TypeInferenceObserver registerMul(CoreInstance templateMul, CoreInstance valueMul, TypeInferenceContext context, TypeInferenceContext targetGenericsContext)
{
Expand Down Expand Up @@ -233,4 +244,18 @@ public TypeInferenceObserver finishedProcessingFunctionExpression(CoreInstance f
activeObserver().finishedProcessingFunctionExpression(functionExpression);
return this;
}

@Override
public TypeInferenceObserver updateFunctionResolvedTypeParameters(Function<?> foundFunction, FunctionType functionType)
{
activeObserver().updateFunctionResolvedTypeParameters(foundFunction, functionType);
return this;
}

@Override
public TypeInferenceObserver updateFunctionResolvedTypeParameterValue(TypeParameter typeParameter, CoreInstance value)
{
activeObserver().updateFunctionResolvedTypeParameterValue(typeParameter, value);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,12 @@ public class TypeInference
public static boolean canProcessLambda(FunctionDefinition<?> lambda, ProcessorState processorState, ProcessorSupport processorSupport)
{
FunctionType functionType = lambda._classifierGenericType()._typeArguments().notEmpty() ? (FunctionType) ImportStub.withImportStubByPass(lambda._classifierGenericType()._typeArguments().getFirst()._rawType(), processorSupport) : null;
if (functionType != null)
return (functionType == null) || functionType._parameters().noneSatisfy(parameter ->
{
for (VariableExpression parameter : functionType._parameters())
{
GenericType genericType = parameter._genericType();
if (genericType == null || (!org.finos.legend.pure.m3.navigation.generictype.GenericType.isGenericTypeConcrete(genericType) && !processorState.getTypeInferenceContext().isTypeParameterResolved(genericType)))
{
return false;
}
}
}
return true;
GenericType genericType = parameter._genericType();
return (genericType == null) ||
(!org.finos.legend.pure.m3.navigation.generictype.GenericType.isGenericTypeConcrete(genericType) && !processorState.getTypeInferenceContext().isTypeParameterResolved(genericType));
});
}

public static void storeInferredTypeParametersInFunctionExpression(FunctionExpression functionExpression, ProcessorState state, ProcessorSupport processorSupport, Function<?> foundFunction, TypeInferenceObserver observer) throws PureCompilationException
Expand All @@ -85,7 +79,8 @@ public static void storeInferredTypeParametersInFunctionExpression(FunctionExpre
observer.updateFunctionResolvedTypeParameterValue(typeParameter, value);
if (value != null)
{
functionExpression._resolvedTypeParametersAdd((GenericType) value);
CoreInstance copy = org.finos.legend.pure.m3.navigation.generictype.GenericType.copyGenericType(value, functionExpression.getSourceInformation(), processorSupport);
functionExpression._resolvedTypeParametersAdd((GenericType) copy);
}
else if (typeInferenceContext.getParent() == null)
{
Expand Down
Loading

0 comments on commit e5617af

Please sign in to comment.