Skip to content

Commit 2434fd3

Browse files
authored
Fix OptionSets in symbol tables (#2705)
Make sure composed tables return all option sets
1 parent 3753314 commit 2434fd3

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/libraries/Microsoft.PowerFx.Core/Public/Config/ComposedReadOnlySymbolTable.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7+
using System.Reflection.Metadata;
78
using Microsoft.PowerFx.Core.Binding;
89
using Microsoft.PowerFx.Core.Binding.BindInfo;
910
using Microsoft.PowerFx.Core.Entities;
@@ -163,6 +164,20 @@ IEnumerable<EnumSymbol> IEnumStore.EnumSymbols
163164
}
164165
}
165166

167+
public override IEnumerable<KeyValuePair<string, OptionSet>> OptionSets
168+
{
169+
get
170+
{
171+
foreach (ReadOnlySymbolTable st in _symbolTables)
172+
{
173+
foreach (KeyValuePair<string, OptionSet> kvp in st.OptionSets)
174+
{
175+
yield return kvp;
176+
}
177+
}
178+
}
179+
}
180+
166181
public virtual bool Lookup(DName name, out NameLookupInfo nameInfo, NameLookupPreferences preferences = NameLookupPreferences.None)
167182
{
168183
foreach (INameResolver table in _symbolTables)

src/libraries/Microsoft.PowerFx.Core/Public/Config/ReadOnlySymbolTable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ public SymbolTable GetMutableCopyOfFunctions()
347347

348348
public IEnumerable<string> FunctionNames => this.Functions.FunctionNames;
349349

350-
public IEnumerable<KeyValuePair<string, OptionSet>> OptionSets => _variables.Where(kvp => kvp.Value.Kind == BindKind.OptionSet)
351-
.Select(kvp => new KeyValuePair<string, OptionSet>(kvp.Key, (OptionSet)kvp.Value.Data));
350+
public virtual IEnumerable<KeyValuePair<string, OptionSet>> OptionSets => _variables.Where(kvp => kvp.Value.Kind == BindKind.OptionSet)
351+
.Select(kvp => new KeyValuePair<string, OptionSet>(kvp.Key, (OptionSet)kvp.Value.Data));
352352

353353
// Which enums are available.
354354
// These do not compose - only bottom one wins.

src/tests/Microsoft.PowerFx.Core.Tests.Shared/SymbolTableTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,25 @@ public void ComposedReadOnlySymbolTableFunctionCacheTest()
306306
Assert.Equal(2, func3.Count());
307307
}
308308

309+
[Fact]
310+
public void OptionSetTests()
311+
{
312+
var os1 = new OptionSet("os1", DisplayNameProvider.New(new Dictionary<DName, DName>() { { new DName("ln1"), new DName("dn1") } }));
313+
var os2 = new OptionSet("os2", DisplayNameProvider.New(new Dictionary<DName, DName>() { { new DName("ln2"), new DName("dn2") }, { new DName("ln3"), new DName("dn3") } }));
314+
315+
var st1 = new SymbolTable();
316+
st1.AddOptionSet(os1);
317+
318+
Assert.Single(st1.OptionSets);
319+
320+
var st2 = new SymbolTable();
321+
st2.AddOptionSet(os2);
322+
323+
var st3 = SymbolTable.Compose(st1, st2);
324+
325+
Assert.Equal(2, st3.OptionSets.Count());
326+
}
327+
309328
[Fact]
310329
public void VoidIsNotAllowed()
311330
{

0 commit comments

Comments
 (0)