Skip to content

Commit 3a0f457

Browse files
committed
Improve isAttrAssign check
* Otherwise `:a == :b` would be true because it's thought to be isAttrAssign as "==" ends with "=". * Still not fully correct, needs ruby/prism#1715
1 parent 02f160a commit 3a0f457

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/java/org/truffleruby/parser/YARPTranslator.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,9 @@ public RubyNode visitCallNode(Nodes.CallNode node) {
579579
// If the receiver is explicit or implicit 'self' then we can call private methods
580580
final boolean ignoreVisibility = node.receiver == null || node.receiver instanceof Nodes.SelfNode;
581581
final boolean isVariableCall = node.isVariableCall();
582-
// this check isn't accurate and doesn't handle cases like #===, #!=, a.foo=(42)
582+
// This isn't fully accurate and doesn't handle cases like #===, #!=, a.foo=(42)
583583
// the issue is tracked in https://github.com/ruby/prism/issues/1715
584-
final boolean isAttrAssign = methodName.endsWith("=");
584+
final boolean isAttrAssign = isAttrAssign(node.name);
585585
final boolean isSafeNavigation = node.isSafeNavigation();
586586

587587
// No need to copy the array for call(*splat), the elements will be copied to the frame arguments
@@ -733,6 +733,14 @@ private ArgumentsDescriptor getKeywordArgumentsDescriptor(Nodes.Node[] arguments
733733
}
734734
}
735735

736+
private boolean isAttrAssign(String methodName) {
737+
if (!methodName.endsWith("=") || methodName.length() < 2) {
738+
return false;
739+
}
740+
char before = methodName.charAt(methodName.length() - 2);
741+
return before != '=' && before != '!' && before != '<' && before != '>';
742+
}
743+
736744
@Override
737745
public RubyNode visitCallOperatorWriteNode(Nodes.CallOperatorWriteNode node) {
738746
return defaultVisit(node);

0 commit comments

Comments
 (0)