Issue 62: can generate some uncompileable java code #111

Open
consiliens opened this Issue Aug 26, 2011 · 4 comments

Projects

None yet

3 participants

@consiliens

"
Reported by rogerpack2005, May 28, 2011

class RubyObj

end

# should I make this class static? cache it [in a hash]?
class RubyInt < RubyObj
  def initialize(a:int) # numeric ?
  end

  def -(o:RubyObj):RubyObj
  end

end

RubyInt.new(1) - RubyInt.new(2)

results in java code that produces:

$ javac Fail\mr.java
Fail\mr.java:5: not a statement
    (new RubyInt(1) - new RubyInt(2));
    ^

Comment 1 by rogerpack2005, Jun 3, 2011
I guess this one is actually ok...? It's a "mirah can compile this, but javac just can't" fella?
-r
"
http://code.google.com/p/mirah/issues/detail?id=62

@baroquebobcat
Member

@rdp We could have the compiler view operators as aliases for methods(eg - -> subtract) so that javac is happy & so that interacting between java and mirah is more friendly. But, it comes at the cost of doing more things under the hood that programmers would need to know about.

@rdp
Collaborator
rdp commented Aug 29, 2011

maybe we should warn "warning, method is unusable by standard java code"?

@rdp
Collaborator
rdp commented Aug 29, 2011

Or it could just rename things like scala does: http://stackoverflow.com/questions/1492767/scala-in-java-code-colon (- becomes $minus or the like). I don't think it would confuse developers too much since they're pretty uncommon (defining << et al), and as long as they're universally translated it shouldn't cause problems, but would cause java code generated to be compilable, and callable by "pure java" classes too, which could be nice for the long term.

-roger-

@baroquebobcat
Member

I'd like to have the source generator change operators names to ones typically used by Java library classes for the purpose.

eg + -> add, - -> subtract, * -> multiply

I guess the problem w/ that would be that if there was an add method already defined, there'd be an error. Hmm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment