Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Inference: retrieve generic parameter instantiated type #49

Open
wants to merge 1 commit into
base: metadata-provider
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Backend/Analyses/TypeInferenceAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Backend.Model;
using Model.ThreeAddressCode.Values;
using Backend.Utils;
using Model;

namespace Backend.Analyses
{
Expand Down Expand Up @@ -56,6 +57,27 @@ public override void Visit(MethodCallInstruction instruction)
if (instruction.HasResult)
{
instruction.Result.Type = instruction.Method.ReturnType;

// if returnType is a genericParameter that is instantiated, then use its instantiated type
if (instruction.Method.ReturnType is IGenericParameterReference genericParameterReference)
{
IList<IType> genericArguments;
switch (genericParameterReference.Kind)
{
case GenericParameterKind.Type:
genericArguments = ((IBasicType) genericParameterReference.GenericContainer).GenericArguments;
break;
case GenericParameterKind.Method:
genericArguments = ((IMethodReference) genericParameterReference.GenericContainer).GenericArguments;
break;
default:
throw genericParameterReference.Kind.ToUnknownValueException();
}
if (genericArguments.Count > 0)
{
instruction.Result.Type = genericArguments[genericParameterReference.Index];
}
}
}

// Skip implicit "this" parameter.
Expand Down