Repository: chimpler/pyhocon

Issue:
Substitution fails for nested sections
## Description
Hi!

We have come across an issue where pyhocon is unable to resolve a nested substitution that should be resolvable, according to the HOCON specification.

## Example
`base.conf`:
```hocon
foo {
  foo-inner {
    pre-foo = 1
    foo-sub = ${foo.foo-inner.pre-foo}${foo.foo-inner.bar}
  }
}

bar {
  bar-inner {
    foo-sub = ${foo.foo-inner.foo-sub}
  }
}
```

`child.conf`:
```hocon
include required("base.conf")

foo {
  foo-inner {
    bar = 1
  }
}
```

### Expected result
```hocon
foo {
  foo-inner {
    pre-foo = 1
    foo-sub = 11
    bar = 1
  }
}

bar {
  bar-inner {
    foo-sub = 11
  }
}
```

### Actual result
```
pyhocon.exceptions.ConfigSubstitutionException: Cannot resolve ${foo.foo-inner.foo-sub}: (line: 10, col: 15). Check for cycles.
```

**If the variables are moved from `(foo/bar)-inner` to `(foo/bar)`, the substitution works as expected.**

Discussion:

Patch:
diff --git a/pyhocon/config_parser.py b/pyhocon/config_parser.py
index 3b732ce..7ffdb88 100644
--- a/pyhocon/config_parser.py
+++ b/pyhocon/config_parser.py
@@ -660,7 +660,8 @@ class ConfigParser(object):
                         cache_values = cache.get(substitution)
                         if cache_values is None:
                             continue
-                    if not isinstance(resolved_value, ConfigValues):
+
+                    if resolved_value:
                         cache_values.append(substitution)
                         overrides = [s for s in substitutions if s.parent.overridden_value == substitution.parent]
                         if len(overrides) > 0:
diff --git a/samples/substitutions.d/base.conf b/samples/substitutions.d/base.conf
new file mode 100644
index 0000000..1bfcc19
--- /dev/null
+++ b/samples/substitutions.d/base.conf
@@ -0,0 +1,12 @@
+foo {
+  foo-inner {
+    pre-foo = 1
+    foo-sub = ${foo.foo-inner.pre-foo}${foo.foo-inner.bar}
+  }
+}
+
+bar {
+  bar-inner {
+    foo-sub = ${foo.foo-inner.foo-sub}
+  }
+}
diff --git a/samples/substitutions.d/child.conf b/samples/substitutions.d/child.conf
new file mode 100644
index 0000000..ec96f0b
--- /dev/null
+++ b/samples/substitutions.d/child.conf
@@ -0,0 +1,7 @@
+include required("base.conf")
+
+foo {
+  foo-inner {
+    bar = 1
+  }
+}


Test patch:
diff --git a/tests/test_config_parser.py b/tests/test_config_parser.py
index 001ed1a..de303be 100644
--- a/tests/test_config_parser.py
+++ b/tests/test_config_parser.py
@@ -2632,6 +2632,11 @@ www.example-ö.com {
         assert config == expected
         assert config == json.loads(source)
 
+    def test_nested_substitution(self):
+        config = ConfigFactory.parse_file("samples/substitutions.d/child.conf")
+        assert config.get_int("foo.foo-inner.foo-sub") == 11
+        assert config.get_int("bar.bar-inner.foo-sub") == 11
+
     def test_triple_quotes_keys(self):
         config = ConfigFactory.parse_string("\"\"\"foo\"\"\" = bar")
         assert config['foo'] == 'bar'