Skip to content

Commit a0d1b3e

Browse files
committed
A few more tests. Fix bug in ClrTypeSpec2 dealing with nested-in-generic being used as generic type argument.
1 parent 75a2ade commit a0d1b3e

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

Clojure/Clojure/Lib/ClrTypeSpec2.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ void SetGenericArgumentCount(int count)
498498

499499
void MergeNested(ClrTypeSpec nestedSpec)
500500
{
501+
_assemblyName = nestedSpec.AssemblyName;
501502

502503
// Append all nested names to the current type
503504
if (_nested == null)
@@ -550,7 +551,7 @@ public static ClrTypeSpec Parse(string typeName)
550551
return res;
551552
}
552553

553-
static ClrTypeSpec Parse(string name, ref int p, bool is_recurse, bool allow_aqn, bool allow_mods)
554+
static ClrTypeSpec Parse(string name, ref int p, bool is_recurse, bool allow_aqn, bool junk)
554555
{
555556
// Invariants:
556557
// - On exit p, is updated to pos the current unconsumed character.
@@ -626,22 +627,12 @@ static ClrTypeSpec Parse(string name, ref int p, bool is_recurse, bool allow_aqn
626627
switch (name[pos])
627628
{
628629
case '&':
629-
if (!allow_mods)
630-
{
631-
p = pos;
632-
return data;
633-
}
634630
if (data._isByRef)
635631
throw new ArgumentException("Can't have a byref of a byref", "typeName");
636632

637633
data._isByRef = true;
638634
break;
639635
case '*':
640-
if (!allow_mods)
641-
{
642-
p = pos;
643-
return data;
644-
}
645636
if (data._isByRef)
646637
throw new ArgumentException("Can't have a pointer to a byref type", "typeName");
647638
// take subsequent '*'s too
@@ -654,11 +645,6 @@ static ClrTypeSpec Parse(string name, ref int p, bool is_recurse, bool allow_aqn
654645
data.AddModifier(new ClrPointerSpec(pointer_level));
655646
break;
656647
case ',':
657-
if (!allow_mods)
658-
{
659-
p = pos;
660-
return data;
661-
}
662648
if (is_recurse && allow_aqn)
663649
{
664650
int end = pos;
@@ -737,19 +723,15 @@ static ClrTypeSpec Parse(string name, ref int p, bool is_recurse, bool allow_aqn
737723
pos += 2; // skip "]+" to the start of the nested name
738724
var nested = Parse(name, ref pos, true, false, true);
739725
data.MergeNested(nested);
726+
if (is_recurse)
727+
// We are going to loop and increment pos, but we haven't yet dealt with the character that ended our nested.
728+
// Decrement pos so the loop increment will get us back to this place.
729+
--pos;
740730
}
741731
}
742732
else
743733
{ //array spec
744734

745-
if (!allow_mods)
746-
{
747-
// We have an array spec (a mod) and we are not allowing mods
748-
// Backup to the position of the [ and get us out of here.
749-
p = pos_cache;
750-
return data;
751-
}
752-
753735
int dimensions = 1;
754736
bool bound = false;
755737
while (pos < name.Length && name[pos] != ']')

Clojure/Csharp.Tests/TypeNameTests2/TypeNameParsingTests2.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,44 @@ public void NestedGenericWithModifiers_ParsesCorrectly()
407407
[Test]
408408
public void NestedGenericAsGenericArg_ParsesCorrectly()
409409
{
410-
var spec = ClrTypeSpec.Parse("A[B+C[D]]");
410+
var spec = ClrTypeSpec.Parse("A[B+C[T]]");
411411
var cmp = TypeSpecComparer.Create("A", 1)
412412
.WithGenericParams(
413413
TypeSpecComparer.Create("B").WithNested(("C", 1))
414414
.WithGenericParams(
415-
TypeSpecComparer.Create("D")));
415+
TypeSpecComparer.Create("T")));
416+
Assert.That(cmp.SameAs(spec), Is.True);
417+
418+
419+
spec = ClrTypeSpec.Parse("A[B+C[T]+D]");
420+
cmp = TypeSpecComparer.Create("A", 1)
421+
.WithGenericParams(
422+
TypeSpecComparer.Create("B").WithNested(("C", 1), ("D", 0))
423+
.WithGenericParams(
424+
TypeSpecComparer.Create("T")));
425+
Assert.That(cmp.SameAs(spec), Is.True);
426+
427+
428+
spec = ClrTypeSpec.Parse("A[B+C[T]]+D");
429+
cmp = TypeSpecComparer.Create("A", 1)
430+
.WithNested("D")
431+
.WithGenericParams(
432+
TypeSpecComparer.Create("B").WithNested(("C", 1))
433+
.WithGenericParams(
434+
TypeSpecComparer.Create("T")));
435+
Assert.That(cmp.SameAs(spec), Is.True);
436+
437+
438+
spec = ClrTypeSpec.Parse("A[B+C[T],D[U]+E]+F");
439+
cmp = TypeSpecComparer.Create("A", 2)
440+
.WithNested("F")
441+
.WithGenericParams(
442+
TypeSpecComparer.Create("B")
443+
.WithNested(("C", 1))
444+
.WithGenericParams(TypeSpecComparer.Create("T")),
445+
TypeSpecComparer.Create("D", 1)
446+
.WithNested("E")
447+
.WithGenericParams(TypeSpecComparer.Create("U")));
416448
Assert.That(cmp.SameAs(spec), Is.True);
417449
}
418450

0 commit comments

Comments
 (0)