Skip to content

Commit e0ef0e9

Browse files
authored
Warnings for Lisp code point to Lisp code (#457)
* Warnings for Lisp code point to Lisp code * fix tests * k
1 parent 4273509 commit e0ef0e9

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/basilisp/lang/compiler/generator.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,8 @@ def _def_to_py_ast( # pylint: disable=too-many-branches
664664
# Warn if this symbol is potentially being redefined
665665
if __should_warn_on_redef(ctx, defsym, safe_name, def_meta):
666666
logger.warning(
667-
f"redefining local Python name '{safe_name}' in module '{ctx.current_ns.module.__name__}'"
667+
f"redefining local Python name '{safe_name}' in module "
668+
f"'{ctx.current_ns.module.__name__}' ({node.env.ns}:{node.env.line})"
668669
)
669670

670671
meta_ast = gen_py_ast(ctx, node.meta)
@@ -2020,7 +2021,10 @@ def _var_sym_to_py_ast(
20202021
)
20212022

20222023
if ctx.warn_on_var_indirection:
2023-
logger.warning(f"could not resolve a direct link to Var '{var_name}'")
2024+
logger.warning(
2025+
f"could not resolve a direct link to Var '{var_name}' "
2026+
f"({node.env.ns}:{node.env.line})"
2027+
)
20242028

20252029
return __var_find_to_py_ast(var_name, ns_name, py_var_ctx)
20262030

tests/basilisp/compiler_test.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def test_warn_on_redef_if_warn_on_redef_meta_missing(
330330
assert (
331331
"basilisp.lang.compiler.generator",
332332
logging.WARNING,
333-
f"redefining local Python name 'unique_djhvyz' in module '{ns.name}'",
333+
f"redefining local Python name 'unique_djhvyz' in module '{ns.name}' (test:2)",
334334
) in caplog.record_tuples
335335

336336
def test_redef_vars(self, ns: runtime.Namespace, caplog):
@@ -343,7 +343,7 @@ def test_redef_vars(self, ns: runtime.Namespace, caplog):
343343
"""
344344
)
345345
assert (
346-
f"redefining local Python name 'orig' in module '{ns.name}'"
346+
f"redefining local Python name 'orig' in module '{ns.name}' (test:2)"
347347
) not in caplog.messages
348348

349349
def test_def_dynamic(self, ns: runtime.Namespace):
@@ -3011,7 +3011,7 @@ def test_warning_for_cross_ns_reference(self, other_ns, caplog):
30113011
assert (
30123012
"basilisp.lang.compiler.generator",
30133013
logging.WARNING,
3014-
"could not resolve a direct link to Var 'm'",
3014+
"could not resolve a direct link to Var 'm' (test:1)",
30153015
) in caplog.record_tuples
30163016

30173017
def test_no_warning_for_cross_ns_reference_if_warning_disabled(
@@ -3020,21 +3020,25 @@ def test_no_warning_for_cross_ns_reference_if_warning_disabled(
30203020
lcompile(
30213021
"(fn [] (other.ns/m :z))", opts={compiler.WARN_ON_VAR_INDIRECTION: False}
30223022
)
3023-
assert ("could not resolve a direct link to Var 'm'") not in caplog.messages
3023+
assert (
3024+
"could not resolve a direct link to Var 'm' (test:1)"
3025+
) not in caplog.messages
30243026

30253027
def test_warning_for_cross_ns_alias_reference(self, other_ns, caplog):
30263028
lcompile("(fn [] (other/m :z))", opts={compiler.WARN_ON_VAR_INDIRECTION: True})
30273029
assert (
30283030
"basilisp.lang.compiler.generator",
30293031
logging.WARNING,
3030-
"could not resolve a direct link to Var 'm'",
3032+
"could not resolve a direct link to Var 'm' (test:1)",
30313033
) in caplog.record_tuples
30323034

30333035
def test_no_warning_for_cross_ns_alias_reference_if_warning_disabled(
30343036
self, other_ns, caplog
30353037
):
30363038
lcompile("(fn [] (other/m :z))", opts={compiler.WARN_ON_VAR_INDIRECTION: False})
3037-
assert ("could not resolve a direct link to Var 'm'") not in caplog.messages
3039+
assert (
3040+
"could not resolve a direct link to Var 'm' (test:1)"
3041+
) not in caplog.messages
30383042

30393043
def test_warning_on_imported_name(self, ns: runtime.Namespace, caplog):
30403044
"""Basilisp should be able to directly resolve a link to cross-namespace
@@ -3047,7 +3051,7 @@ def test_warning_on_imported_name(self, ns: runtime.Namespace, caplog):
30473051
opts={compiler.WARN_ON_VAR_INDIRECTION: True},
30483052
)
30493053
assert (
3050-
"could not resolve a direct link to Python variable 'string/m'"
3054+
"could not resolve a direct link to Python variable 'string/m' (test:1)"
30513055
) not in caplog.messages
30523056

30533057
def test_exception_raised_for_nonexistent_imported_name(

0 commit comments

Comments
 (0)