[#104] | project: compiler | priority: medium | category: feature | |
---|---|---|---|---|
submitter | assigned to | status | date submitted | |
Matthias | Martin | won't fix | 2003-09-02 22:47:13.0 | |
subject | Using + with subtypes of Int | |||
code |
object T { def add(x: Byte, y: Byte): Byte = x + y; } |
|||
what happened | It is not possible to use + or - with arguments of type Byte, Short, Char without getting result values of type Int (instead of Byte, Short, or Char). Consequently, the program above is not correct. In practice it happens quite often (especially for Char) that one wants to take a character and add a value to it to get a new character. In Scala, that's not possible without using type casts. Is this really intended? |
|||
what expected | ||||
[back to overview] |
Martin edited on 2003-09-03 12:55:19.0 |
Yes, this corresponds to what Java does also:
home/odersky/test/gjc> more plus.java class plus { static byte foo(byte x, byte y) { return x + y; } } /home/odersky/test/gjc> jc plus.java plus.java:4: possible loss of precision found : int required: byte return x + y; ^ 1 error |