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

Config.Root should contain fallback values #181

Merged
merged 5 commits into from
Jan 16, 2020

Conversation

IgorFedchenko
Copy link
Contributor

Close #177

The issue turned out to be little bit deeper then I thought at start.
Assuming that config has fallback values, config.Root.GetObject() returns object not containing fallback values because Root property of type HoconValue does not contain them.

Hocon core library does not work with fallbacks in any way - so HoconValue does not have any information about possible fallbacks it has.
So the way to go is to aggregate all fallback values into Root property, which is what I am doing. Since HoconValue type is mutable, making separate value and putting values in reverse order - to support proper fallbacks ordering when hocon will merge inner objects.

Also, seems like few more functions in Config file were trying to check if any fallbacks exist - there is no need to do this anymore, since we always have magic Root value that already contains aggregated HoconValue with all fallbacks included.

Added more tests to verify that deep objects merge correctly. And, important thing - fixed config.ToString(useFallbackValues: true) implementation, since old one was dropping original values and was only using fallback values. Updated test for this as well.

}
catch
{
if (throwIfNotFound)
throw;

result = Fallback?.GetNode(path);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to check for fallback here anymore - if Root does not have it, then it just does not exist

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better - I like this change. Makes sense.

@@ -123,12 +138,6 @@ public virtual Config GetConfig(string path)
public virtual Config GetConfig(HoconPath path)
{
var value = GetNode(path);
if (Fallback != null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, since GetNode is loading node from Root, which already has all fallback info.

@@ -188,19 +197,13 @@ public virtual Config WithFallback(Config fallback)
public override IEnumerable<KeyValuePair<string, HoconField>> AsEnumerable()
{
var used = new HashSet<string>();
var current = this;
while (current != null)
foreach (var kvp in Root.GetObject())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since now Root includes fallbacks, no need to iterate them

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}
catch
{
if (throwIfNotFound)
throw;

result = Fallback?.GetNode(path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better - I like this change. Makes sense.

}

[Fact]
public void HoconValue_GetObject_should_use_fallback_values_with_complex_objects()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see some more complex test cases. This is great work.

@Aaronontheweb Aaronontheweb merged commit d945735 into akkadotnet:dev Jan 16, 2020
@IgorFedchenko IgorFedchenko deleted the fix/config-root-fallback branch January 17, 2020 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HoconValue.GetObject() ignores fallback values
2 participants