Skip to content

Commit 4a87aab

Browse files
authored
Merge pull request #1906 from certik/loc_fix
Fix ExternalSymbol location
2 parents c32fe9c + abd8709 commit 4a87aab

File tree

6 files changed

+34
-46
lines changed

6 files changed

+34
-46
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ ASR::symbol_t* import_from_module(Allocator &al, ASR::Module_t *m, SymbolTable *
445445
name.from_str(al, new_sym_name);
446446
char *cname = name.c_str(al);
447447
ASR::asr_t *fn = ASR::make_ExternalSymbol_t(
448-
al, mfn->base.base.loc,
448+
al, loc,
449449
/* a_symtab */ current_scope,
450450
/* a_name */ cname,
451451
(ASR::symbol_t*)mfn,
@@ -461,7 +461,7 @@ ASR::symbol_t* import_from_module(Allocator &al, ASR::Module_t *m, SymbolTable *
461461
name.from_str(al, new_sym_name);
462462
char *cname = name.c_str(al);
463463
ASR::asr_t *est = ASR::make_ExternalSymbol_t(
464-
al, st->base.base.loc,
464+
al, loc,
465465
/* a_symtab */ current_scope,
466466
/* a_name */ cname,
467467
(ASR::symbol_t*)st,
@@ -475,7 +475,7 @@ ASR::symbol_t* import_from_module(Allocator &al, ASR::Module_t *m, SymbolTable *
475475
name.from_str(al, new_sym_name);
476476
char *cname = name.c_str(al);
477477
ASR::asr_t *est = ASR::make_ExternalSymbol_t(
478-
al, et->base.base.loc,
478+
al, loc,
479479
/* a_symtab */ current_scope,
480480
/* a_name */ cname,
481481
(ASR::symbol_t*)et,
@@ -491,7 +491,7 @@ ASR::symbol_t* import_from_module(Allocator &al, ASR::Module_t *m, SymbolTable *
491491
name.from_str(al, new_sym_name);
492492
char *cname = name.c_str(al);
493493
ASR::asr_t *v = ASR::make_ExternalSymbol_t(
494-
al, mv->base.base.loc,
494+
al, loc,
495495
/* a_symtab */ current_scope,
496496
/* a_name */ cname,
497497
(ASR::symbol_t*)mv,
@@ -505,7 +505,7 @@ ASR::symbol_t* import_from_module(Allocator &al, ASR::Module_t *m, SymbolTable *
505505
name.from_str(al, new_sym_name);
506506
char *cname = name.c_str(al);
507507
ASR::asr_t *v = ASR::make_ExternalSymbol_t(
508-
al, gt->base.base.loc,
508+
al, loc,
509509
/* a_symtab */ current_scope,
510510
/* a_name */ cname,
511511
(ASR::symbol_t*)gt,
@@ -4253,14 +4253,14 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
42534253
}
42544254
std::string new_sym_name = ASRUtils::get_mangled_name(m, remote_sym);
42554255
ASR::symbol_t *t = import_from_module(al, m, current_scope, msym,
4256-
remote_sym, new_sym_name, x.base.base.loc, true);
4256+
remote_sym, new_sym_name, x.m_names[i].loc, true);
42574257
if (current_scope->get_scope().find(new_sym_name) != current_scope->get_scope().end()) {
42584258
ASR::symbol_t *old_sym = current_scope->get_scope().find(new_sym_name)->second;
42594259
diag.add(diag::Diagnostic(
42604260
"The symbol '" + new_sym_name + "' imported from " + std::string(m->m_name) +" will shadow the existing symbol '" + new_sym_name + "'",
42614261
diag::Level::Warning, diag::Stage::Semantic, {
4262-
diag::Label("new symbol", {x.m_names[i].loc}),
4263-
diag::Label("old symbol implementation", {old_sym->base.loc}),
4262+
diag::Label("old symbol", {old_sym->base.loc}),
4263+
diag::Label("new symbol", {t->base.loc}),
42644264
})
42654265
);
42664266
current_scope->overwrite_symbol(new_sym_name, t);

tests/reference/asr-modules_02-ec92e6f.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"stdout": "asr-modules_02-ec92e6f.stdout",
99
"stdout_hash": "2b9767d477601b562ca13e1d770d84bafad8f2647fb778d52fc20d0d",
1010
"stderr": "asr-modules_02-ec92e6f.stderr",
11-
"stderr_hash": "910bed77716460a8f8712eac5e5818c55b7744f45a4a36aa257f3527",
11+
"stderr_hash": "132af04271d3bfd523848990e734bfa3c0aed6e4b85ec4eb87e66720",
1212
"returncode": 0
1313
}
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
warning: The symbol 'f' imported from modules_02b will shadow the existing symbol 'f'
2-
--> tests/../integration_tests/modules_02.py:1:28
2+
--> tests/../integration_tests/modules_02.py:1:25
33
|
44
1 | from modules_02b import f, f
5-
| ^ new symbol
6-
7-
--> tests/../integration_tests/modules_02b.py:3:1 - 5:16
8-
|
9-
3 | def f():
10-
| ^^^^^^^^...
11-
...
5+
| ^ old symbol
126
|
13-
5 | print("f()")
14-
| ...^^^^^^^^^^^^^^^^ old symbol implementation
7+
1 | from modules_02b import f, f
8+
| ^ new symbol

tests/reference/asr_json-modules_02-70a491a.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr_json-modules_02-70a491a.stdout",
9-
"stdout_hash": "baae33b908a2ae0da9c7dd50b6307a768b0360e514987d70d3e37dc4",
9+
"stdout_hash": "a2e97444a1e8cb6a623037d104f24628adeea2d3af9cae5d680a5423",
1010
"stderr": "asr_json-modules_02-70a491a.stderr",
11-
"stderr_hash": "67b8bf471b878cb687ed200fe5d207b6b4acb9d1e1096a930576fba9",
11+
"stderr_hash": "074c73dfbd40f5246b5f400ebe4b1597683344d0c6353cbffc6f32c8",
1212
"returncode": 0
1313
}
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
warning: The symbol 'f' imported from modules_02b will shadow the existing symbol 'f'
2-
--> tests/../integration_tests/modules_02.py:1:28
2+
--> tests/../integration_tests/modules_02.py:1:25
33
|
44
1 | from modules_02b import f, f
5-
| ^ new symbol
6-
7-
--> tests/../integration_tests/modules_02b.py:3:1 - 5:16
8-
|
9-
3 | def f():
10-
| ^^^^^^^^...
11-
...
5+
| ^ old symbol
126
|
13-
5 | print("f()")
14-
| ...^^^^^^^^^^^^^^^^ old symbol implementation
7+
1 | from modules_02b import f, f
8+
| ^ new symbol

tests/reference/asr_json-modules_02-70a491a.stdout

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@
100100
"access": "Public"
101101
},
102102
"loc": {
103-
"first": 157,
104-
"last": 189,
105-
"first_filename": "tests/../integration_tests/modules_02b.py",
106-
"first_line": 3,
107-
"first_column": 1,
108-
"last_filename": "tests/../integration_tests/modules_02b.py",
109-
"last_line": 5,
110-
"last_column": 16
103+
"first": 27,
104+
"last": 27,
105+
"first_filename": "tests/../integration_tests/modules_02.py",
106+
"first_line": 1,
107+
"first_column": 28,
108+
"last_filename": "tests/../integration_tests/modules_02.py",
109+
"last_line": 1,
110+
"last_column": 28
111111
}
112112
},
113113
"main0": {
@@ -822,14 +822,14 @@
822822
"access": "Public"
823823
},
824824
"loc": {
825-
"first": 191,
826-
"last": 215,
827-
"first_filename": "tests/../integration_tests/modules_02c.py",
825+
"first": 154,
826+
"last": 154,
827+
"first_filename": "tests/../integration_tests/modules_02b.py",
828828
"first_line": 1,
829-
"first_column": 1,
830-
"last_filename": "tests/../integration_tests/modules_02c.py",
831-
"last_line": 2,
832-
"last_column": 16
829+
"first_column": 25,
830+
"last_filename": "tests/../integration_tests/modules_02b.py",
831+
"last_line": 1,
832+
"last_column": 25
833833
}
834834
}
835835
}

0 commit comments

Comments
 (0)