Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Bond.Parser.CLI/Bond.Parser.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackAsTool>true</PackAsTool>
<ToolCommandName>bbc</ToolCommandName>
<PackageId>bbc</PackageId>
<Version>0.2.1</Version>
<Version>0.2.2</Version>
<Authors>Mirco De Zorzi</Authors>
<Description>Bond IDL compiler and toolchain</Description>
<RootNamespace>Bond.Parser.CLI</RootNamespace>
Expand Down
20 changes: 20 additions & 0 deletions Bond.Parser.Tests/ParserFacadeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -921,4 +921,24 @@ struct User {
}

#endregion

#region Issues

[Fact]
public async Task SetWithAlias_IsParsed()
{
var input = """
namespace Test
using guid = string;
struct User {
0: required map<guid, int16> properties;
}
""";

var result = await Parse(input);

result.Success.Should().BeTrue();
}

#endregion
}
39 changes: 31 additions & 8 deletions Bond.Parser/Parser/SemanticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,47 @@ private static void CheckForDuplicates<T>(IEnumerable<T> items, string context,
}

/// <summary>
/// Resolves type aliases to their underlying types
/// Resolves type aliases to their underlying types, including nested container types
/// </summary>
private BondType ResolveAliases(BondType type, Namespace[] namespaces)
{
if (type is not BondType.UnresolvedUserType unresolved)
return ResolveAliases(type, namespaces, new HashSet<Declaration>());
}

private BondType ResolveAliases(BondType type, Namespace[] namespaces, HashSet<Declaration> visiting)
{
return type switch
{
return type;
}
BondType.UnresolvedUserType unresolved => ResolveAliasType(unresolved, namespaces, visiting),
BondType.List list => new BondType.List(ResolveAliases(list.ElementType, namespaces, visiting)),
BondType.Vector vector => new BondType.Vector(ResolveAliases(vector.ElementType, namespaces, visiting)),
BondType.Set set => new BondType.Set(ResolveAliases(set.KeyType, namespaces, visiting)),
BondType.Map map => new BondType.Map(
ResolveAliases(map.KeyType, namespaces, visiting),
ResolveAliases(map.ValueType, namespaces, visiting)),
BondType.Nullable nullable => new BondType.Nullable(ResolveAliases(nullable.ElementType, namespaces, visiting)),
BondType.Maybe maybe => new BondType.Maybe(ResolveAliases(maybe.ElementType, namespaces, visiting)),
BondType.Bonded bonded => new BondType.Bonded(ResolveAliases(bonded.StructType, namespaces, visiting)),
_ => type
};
}

private BondType ResolveAliasType(BondType.UnresolvedUserType unresolved, Namespace[] namespaces, HashSet<Declaration> visiting)
{
var decl = _symbolTable.FindSymbol(unresolved.QualifiedName, namespaces);
if (decl is not AliasDeclaration alias)
{
return unresolved;
}

// Recursively resolve aliases
if (decl is AliasDeclaration alias)
if (!visiting.Add(alias))
{
return ResolveAliases(alias.AliasedType, namespaces);
return unresolved;
}

return type;
var resolved = ResolveAliases(alias.AliasedType, namespaces, visiting);
visiting.Remove(alias);
return resolved;
}

private void ValidateField(Field field, Namespace[] namespaces)
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.1
0.2.2
Loading