Skip to content

Commit

Permalink
Strengthen the condition to disallow literals like -"hello"
Browse files Browse the repository at this point in the history
Signed-off-by: Danila Fedorin <[email protected]>
  • Loading branch information
DanilaFe committed Jun 10, 2024
1 parent 26e3a27 commit 8541ba3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tools/chpl-language-server/src/chpl-language-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@
import argparse
import configargparse

REAL_NUMBERIC = (chapel.RealLiteral, chapel.IntLiteral, chapel.UintLiteral)
NUMERIC = REAL_NUMBERIC + (chapel.ImagLiteral,)

def is_basic_literal_like(node: chapel.AstNode) -> Optional[chapel.Literal]:
"""
Check for "basic" literals: basically, 1, "hello", -42, etc.
Expand All @@ -155,7 +158,7 @@ def is_basic_literal_like(node: chapel.AstNode) -> Optional[chapel.Literal]:
if isinstance(node, chapel.OpCall) and node.op() == "-" and node.num_actuals() == 1:
# Do not recurse; do not consider --42 as a basic literal.
act = node.actual(0)
if isinstance(act, chapel.Literal):
if isinstance(act, NUMERIC):
return act

return None
Expand All @@ -177,7 +180,7 @@ def is_literal_like(node: chapel.AstNode) -> bool:
left = is_basic_literal_like(node.actual(0))
right = node.actual(1)

real_number = (chapel.RealLiteral, chapel.IntLiteral)
real_number = REAL_NUMBERIC
imag_number = chapel.ImagLiteral
if isinstance(left, real_number) and isinstance(right, imag_number):
return True
Expand Down

0 comments on commit 8541ba3

Please sign in to comment.