Skip to content

Commit

Permalink
Langkit_Support.Symbols: fix Get_Symbol for null symbols
Browse files Browse the repository at this point in the history
When symbol canonicalization fails, $.Lexer_Implementation.Force_Symbol
calls Get_Symbol passing to it No_Thin_Symbol, so Get_Symbol needs to
support this case.

TN: T923-007
  • Loading branch information
pmderodat committed Sep 23, 2020
1 parent 2580460 commit a556e9b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
6 changes: 5 additions & 1 deletion langkit/support/langkit_support-symbols.adb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ package body Langkit_Support.Symbols is
function Get_Symbol
(Self : Symbol_Table; TS : Thin_Symbol) return Symbol_Type is
begin
return Self.Symbols.Get (Positive (TS));
if TS = No_Thin_Symbol then
return null;
else
return Self.Symbols.Get (Positive (TS));
end if;
end Get_Symbol;

end Langkit_Support.Symbols;
13 changes: 13 additions & 0 deletions testsuite/tests/properties/symbol/extensions/src/pkg.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package body Pkg is

------------------
-- Canonicalize --
------------------

function Canonicalize (Name : Text_Type) return Symbolization_Result is
pragma Unreferenced (Name);
begin
return Create_Error ("no symbol allowed");
end Canonicalize;

end Pkg;
8 changes: 8 additions & 0 deletions testsuite/tests/properties/symbol/extensions/src/pkg.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
with Langkit_Support.Text; use Langkit_Support.Text;
with Libfoolang.Common; use Libfoolang.Common;

package Pkg is

function Canonicalize (Name : Text_Type) return Symbolization_Result;

end Pkg;
12 changes: 6 additions & 6 deletions testsuite/tests/properties/symbol/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
print(d)
sys.exit(1)

try:
result = u.root.p_prop(None)
except libfoolang.PropertyError as exc:
result = '<{}: {}>'.format(type(exc).__name__, exc)

print('p_prop(None) = {}'.format(result))
for n in (None, u.root):
try:
result = libfoolang._py2to3.text_repr(u.root.p_prop(n))
except libfoolang.PropertyError as exc:
result = '<{}: {}>'.format(type(exc).__name__, exc)
print('p_prop({}) = {}'.format(n, result))

print('main.py: Done.')
1 change: 1 addition & 0 deletions testsuite/tests/properties/symbol/test.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
main.py: Running...
p_prop(None) = <PropertyError: cannot get the symbol of a null node>
p_prop(<Example main.txt:1:1-1:8>) = ''
main.py: Done.
Done
7 changes: 5 additions & 2 deletions testsuite/tests/properties/symbol/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""
Test that ".symbol" raises a property error on null nodes.
Test that ".symbol" raises a property error on null nodes or when symbol
canonicalization fails.
"""

from langkit.compile_context import LibraryEntity
from langkit.dsl import ASTNode, T
from langkit.expressions import langkit_property

Expand All @@ -19,5 +21,6 @@ class Example(FooNode):
token_node = True


build_and_run(lkt_file='expected_concrete_syntax.lkt', py_script='main.py')
build_and_run(lkt_file='expected_concrete_syntax.lkt', py_script='main.py',
symbol_canonicalizer=LibraryEntity('Pkg', 'Canonicalize'))
print('Done')

0 comments on commit a556e9b

Please sign in to comment.