Skip to content

Commit e670f4d

Browse files
committed
Langkit_Support.Generic_API: fix handling of null token kinds
1 parent 342b11f commit e670f4d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

langkit/support/langkit_support-generic_api.adb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ package body Langkit_Support.Generic_API is
144144

145145
function Token_Kind_Name (Kind : Token_Kind_Ref) return Name_Type is
146146
begin
147+
Check_Token_Kind (Kind);
147148
return Create_Name (Kind.Id.Token_Kinds (Kind.Index).Name.all);
148149
end Token_Kind_Name;
149150

testsuite/tests/ada_api/generic_api/analysis.adb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ begin
9090
end loop;
9191
New_Line;
9292

93+
Put_Line ("Use of null token kind:");
94+
declare
95+
Dummy : Name_Type;
96+
begin
97+
Dummy := Token_Kind_Name (No_Token_Kind_Ref);
98+
raise Program_Error;
99+
exception
100+
when Exc : Precondition_Failure =>
101+
Put_Line ("Got a Precondition_Failure exception: "
102+
& Exception_Message (Exc));
103+
end;
104+
New_Line;
105+
93106
Put_Line ("Use of null context:");
94107
declare
95108
Dummy : Boolean;

testsuite/tests/ada_api/generic_api/test.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ Token families:
5151
Punctuation
5252
Default_Family
5353

54+
Use of null token kind:
55+
Got a Precondition_Failure exception: null token kind reference
56+
5457
Use of null context:
5558
Got a Precondition_Failure exception: null context
5659

0 commit comments

Comments
 (0)