Skip to content

Commit 6c0234b

Browse files
committed
Fix JRUBY-6383
Scala integration breaks with 1.6.6 This has actually been "broken" since 1.6.0, since we were not defining the symbolic names for any of the $ Scala methods. This fix adds the symbolic names and leaves the originals intact.
1 parent 6ff47b3 commit 6c0234b

File tree

3 files changed

+66
-10
lines changed

3 files changed

+66
-10
lines changed

spec/java_integration/fixtures/MethodNames.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ public void setJConsecutiveCaps(Object value) {}
6363
public String id() {return "foo";}
6464
public String __id__() {return "foo";}
6565

66-
// names that should be fixed by fixScalaNames
67-
public String $bslash() {return "$bslash";}
66+
// names that should get aliases for Scala integration
67+
public String $plus() {return "$plus";}
68+
public String $minus() {return "$minus";}
69+
public String $colon() {return "$colon";}
70+
public String $div() {return "$div";}
71+
public String $eq() {return "$eq";}
72+
public String $less() {return "$less";}
73+
public String $greater() {return "$greater";}
74+
public String $bslash() {return "$bslash";}
75+
public String $hash() {return "$hash";}
76+
public String $times() {return "$times";}
77+
public String $bang() {return "$bang";}
78+
public String $at() {return "$at";}
79+
public String $percent() {return "$percent";}
80+
public String $up() {return "$up";}
81+
public String $amp() {return "$amp";}
82+
public String $tilde() {return "$tilde";}
83+
public String $qmark() {return "$qmark";}
84+
public String $bar() {return "$bar";}
85+
public String $plus$eq() {return "$plus$eq";}
6886
}

spec/java_integration/methods/naming_spec.rb

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,49 @@
146146
obj.__id__.should_not == "foo"
147147
lambda {obj.__send__}.should raise_error(ArgumentError)
148148
end
149-
150-
it "has methods named $bslash" do
151-
members.should have_strings("\\")
149+
150+
it "aliases scala names to symbolic equivalents" do
152151
obj = MethodNames.new
152+
153+
obj.send(:"+").should == "$plus"
154+
obj.send(:"-").should == "$minus"
155+
obj.send(:":").should == "$colon"
156+
obj.send(:"/").should == "$div"
157+
obj.send(:"=").should == "$eq"
158+
obj.send(:"<").should == "$less"
159+
obj.send(:">").should == "$greater"
153160
obj.send(:"\\").should == "$bslash"
161+
obj.send(:"#").should == "$hash"
162+
obj.send(:"*").should == "$times"
163+
obj.send(:"!").should == "$bang"
164+
obj.send(:"@").should == "$at"
165+
obj.send(:"%").should == "$percent"
166+
obj.send(:"^").should == "$up"
167+
obj.send(:"&").should == "$amp"
168+
obj.send(:"~").should == "$tilde"
169+
obj.send(:"?").should == "$qmark"
170+
obj.send(:"|").should == "$bar"
171+
obj.send(:"+=").should == "$plus$eq"
172+
173+
obj.send(:"$plus").should == "$plus"
174+
obj.send(:"$minus").should == "$minus"
175+
obj.send(:"$colon").should == "$colon"
176+
obj.send(:"$div").should == "$div"
177+
obj.send(:"$eq").should == "$eq"
178+
obj.send(:"$less").should == "$less"
179+
obj.send(:"$greater").should == "$greater"
180+
obj.send(:"$bslash").should == "$bslash"
181+
obj.send(:"$hash").should == "$hash"
182+
obj.send(:"$times").should == "$times"
183+
obj.send(:"$bang").should == "$bang"
184+
obj.send(:"$at").should == "$at"
185+
obj.send(:"$percent").should == "$percent"
186+
obj.send(:"$up").should == "$up"
187+
obj.send(:"$amp").should == "$amp"
188+
obj.send(:"$tilde").should == "$tilde"
189+
obj.send(:"$qmark").should == "$qmark"
190+
obj.send(:"$bar").should == "$bar"
191+
obj.send(:"$plus$eq").should == "$plus$eq"
154192
end
155193
end
156194

src/org/jruby/javasupport/JavaClass.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,11 @@ private static void assignAliases(MethodInstaller installer, Map<String, Assigne
745745
addUnassignedAlias("[]=", assignedNames, installer);
746746
}
747747

748+
// Scala aliases for $ method names
749+
if (name.startsWith("$")) {
750+
addUnassignedAlias(fixScalaNames(name), assignedNames, installer);
751+
}
752+
748753
// Add property name aliases
749754
if (javaPropertyName != null) {
750755
if (rubyCasedName.startsWith("get_")) {
@@ -955,11 +960,6 @@ private void setupClassMethods(Class<?> javaClass, InitializerState state) {
955960
Method method = methods[i];
956961
String name = method.getName();
957962

958-
// Fix Scala names to be their Ruby equivalents
959-
if (name.startsWith("$")) {
960-
name = fixScalaNames(name);
961-
}
962-
963963
if (Modifier.isStatic(method.getModifiers())) {
964964
AssignedName assignedName = state.staticNames.get(name);
965965

0 commit comments

Comments
 (0)