Skip to content

Commit de1bb74

Browse files
committed
Work on substitution of generic members.
1 parent fc3d45e commit de1bb74

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

Nitra/DotNetLang/Scopes/NestedSubstScope.n

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,23 @@ namespace DotNet
1515
{
1616
public class NestedSubstScope : TopSubstScope
1717
{
18-
private _parent : TypeSymbol;
18+
private _parent : TypeSymbol;
19+
private _nestedScope : Scope;
1920

20-
public this(typeInfo : GenericTypeSymbol, scope : Scope, args : ImmutableArray[TypeSymbol], parent : TypeSymbol)
21+
public this(typeInfo : GenericTypeSymbol, nestedScope : Scope, args : ImmutableArray[TypeSymbol], parent : TypeSymbol)
2122
{
22-
base(typeInfo, scope, args);
23-
_parent = parent;
23+
base(typeInfo, args);
24+
_parent = parent;
25+
_nestedScope = nestedScope;
26+
}
27+
28+
public override TrySubstTypeParameterSymbol(parameterSymbol : TypeParameterSymbol) : TypeSymbol
29+
{
30+
def result = base.TrySubstTypeParameterSymbol(parameterSymbol);
31+
if (_nestedScope is TopSubstScope as substScope)
32+
substScope.TrySubstTypeParameterSymbol(parameterSymbol);
33+
else
34+
result
2435
}
2536

2637
public override Serialize(writer : System.IO.BinaryWriter, metadataWriter : Nitra.Serialization2.MetadataWriter) : void

Nitra/DotNetLang/Scopes/TopSubstScope.n

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ namespace DotNet
2020
private _args : ImmutableArray[TypeSymbol];
2121
private _typeParamsMap : Hashtable[int, TypeSymbol];
2222

23-
public this(typeInfo : GenericTypeSymbol, _scope : Scope, args : ImmutableArray[TypeSymbol])
23+
public this(typeInfo : GenericTypeSymbol, nestedScope : Scope, args : ImmutableArray[TypeSymbol]) { this(typeInfo, args) }
24+
25+
public this(typeInfo : GenericTypeSymbol, args : ImmutableArray[TypeSymbol])
2426
{
2527
_typeInfo = typeInfo;
2628
_args = args;
@@ -38,20 +40,23 @@ namespace DotNet
3840
// TODO: add type subst
3941
public override AllSymbols : Seq[DeclarationSymbol] { get { _typeInfo.Scope.AllSymbols } }
4042

43+
public virtual TrySubstTypeParameterSymbol(parameterSymbol : TypeParameterSymbol) : TypeSymbol
44+
{
45+
mutable result;
46+
if (_typeParamsMap.TryGetValue(parameterSymbol.Id, out result))
47+
result
48+
else
49+
{
50+
assert2(false, "Unmapped TypeParameterSymbol!");
51+
parameterSymbol
52+
}
53+
}
54+
4155
private TrySubst(type : TypeSymbol) : TypeSymbol
4256
{
4357
match (type)
4458
{
45-
| TypeParameterSymbol =>
46-
mutable result;
47-
if (_typeParamsMap.TryGetValue(type.Id, out result))
48-
result
49-
else
50-
{
51-
assert2(false, "Unmapped TypeParameterSymbol!");
52-
type
53-
}
54-
59+
| TypeParameterSymbol as parameterSymbol => TrySubstTypeParameterSymbol(parameterSymbol)
5560
| ConstructedTypeSymbol as cts =>
5661
def typeInfo = cts.TypeInfo;
5762
def args = cts.Args;

0 commit comments

Comments
 (0)