Skip to content

Commit

Permalink
Try to resolve concatenations using built-in operators first.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roldak committed Nov 22, 2023
1 parent f59cbfc commit 69edaa2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 12 additions & 8 deletions ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -13621,9 +13621,19 @@ def xref_equation():
),
concat_operand=Entity.other_operands.at(pos),
right=Entity.other_operands.at(pos).operand: Or(
# TODO: this is implementation is actually not correct
# w.r.t. visibility (eng/libadalang/libadalang#1138).

# Find the subprogram corresponding to:
# "&" (left, right).
# First, try to resolve this operator using built-in
# operators only.
Entity.operator_no_subprogram_equation(
left, concat_operand, right
),

# If that didn't work, try to resolve it by considering
# visible user-defined overloads of "&". NOTE: for
# performance reasons it is better to first try the
# built-in operators first.
concat_subprograms.logic_any(
lambda subp: Let(
lambda spec=subp.subp_spec_or_null:
Expand All @@ -13637,12 +13647,6 @@ def xref_equation():
spec)
)
)
),
# When no subprogram is found for this concat operator,
# use this equation to infer it's type depending on the
# context.
Entity.operator_no_subprogram_equation(
left, concat_operand, right
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Expr: <ConcatOperand test.adb:11:20-11:23>
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
Expr: <OpConcat "&" test.adb:11:20-11:21>
references: <DefiningName ""&"" pkg.ads:2:13-2:16>
references: None
type: None
expected type: None
Expr: <Id "B" test.adb:11:22-11:23>
Expand Down Expand Up @@ -97,7 +97,7 @@ Expr: <ConcatOperand test_2.adb:10:20-10:23>
type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
expected type: <ConcreteTypeDecl ["String"] __standard:105:3-105:57>
Expr: <OpConcat "&" test_2.adb:10:20-10:21>
references: <DefiningName ""&"" test_2.adb:4:13-4:16>
references: None
type: None
expected type: None
Expr: <Id "B" test_2.adb:10:22-10:23>
Expand Down

0 comments on commit 69edaa2

Please sign in to comment.