Skip to content

Commit af28206

Browse files
authored
Fixed a bug where private Vars could be referenced from a Namespace via alias (#514)
1 parent 437bfe3 commit af28206

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
* Fixed a reader bug where no exception was being thrown splicing reader conditional forms appeared outside of valid splicing contexts (#470)
2929
* Fixed a bug where fully Namespace-qualified symbols would not resolve if the current Namespace did not alias the referenced Namespace (#479)
3030
* Fixed a bug where the `quote` special form allowed more than one argument and raised an unintended exception when no argument was provided (#497)
31-
* Fixed a bug where compiler options specified via command-line argument or environment variable were not honored by the importer (#???)
31+
* Fixed a bug where compiler options specified via command-line argument or environment variable were not honored by the importer (#507)
32+
* Fixed a bug where private Vars from other Namespaces could be referenced if the Namespace was aliased when it was required (#514)
3233

3334
## [v0.1.dev12] - 2020-01-26
3435
### Added

src/basilisp/lang/compiler/analyzer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,11 @@ def __resolve_namespaced_symbol_in_ns( # pylint: disable=too-many-branches
24852485
f"unable to resolve symbol '{sym.symbol(form.name, ns_sym.name)}' in this context",
24862486
form=form,
24872487
)
2488+
elif v.meta is not None and v.meta.val_at(SYM_PRIVATE_META_KEY, False):
2489+
raise AnalyzerException(
2490+
f"cannot resolve private Var {form.name} from namespace {form.ns}",
2491+
form=form,
2492+
)
24882493
return VarRef(form=form, var=v, env=ctx.get_node_env(pos=ctx.syntax_position),)
24892494

24902495
return None

tests/basilisp/compiler_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,6 +3255,27 @@ def test_aliased_var_does_not_resolve(
32553255
finally:
32563256
runtime.Namespace.remove(other_ns_name)
32573257

3258+
def test_private_aliased_var_does_not_resolve(
3259+
self, lcompile: CompileFn, ns: runtime.Namespace
3260+
):
3261+
current_ns: runtime.Namespace = ns
3262+
other_ns_name = sym.symbol("other.ns")
3263+
private_var_sym = sym.symbol("m")
3264+
try:
3265+
other_ns = get_or_create_ns(other_ns_name)
3266+
current_ns.add_alias(other_ns, sym.symbol("other"))
3267+
3268+
private_var = Var(
3269+
other_ns, private_var_sym, meta=lmap.map({SYM_PRIVATE_META_KEY: True})
3270+
)
3271+
private_var.value = kw.keyword("private-var")
3272+
other_ns.intern(private_var_sym, private_var)
3273+
3274+
with pytest.raises(compiler.CompilerException):
3275+
lcompile("(other/m :arg)")
3276+
finally:
3277+
runtime.Namespace.remove(other_ns_name)
3278+
32583279
def test_aliased_macro_symbol_resolution(
32593280
self, lcompile: CompileFn, ns: runtime.Namespace
32603281
):

0 commit comments

Comments
 (0)