X10
  1. X10
  2. XTENLANG-1146

Fully implement coercion/conversion operations between all sensible pairs of built-in primitives

    Details

    • Number of attachments :
      2

      Description

      I can't coerce a UByte to an Int:

      public class ConvUByteToInt {
        public static def main(argv:Rail[String]!) {
          val a = (123 as UByte) as Int;
        }
      }
      

      /Users/bard/x10/jira/jonv/ConvUByteToInt.x10:3: Cannot cast expression to type.
      Expression: (x10.lang.UByte.operator_as(123))
      Expression type: x10.lang.UByte
      To type: x10.lang.Int
      1 error.

      Same goes for UShort and ULong, though not UInt.

      1. coerceUnsigned.patch
        3 kB
        Josh Milthorpe
      2. TestCoerceUnsigned.x10
        0.3 kB
        Josh Milthorpe

        Issue Links

          Activity

          Hide
          Igor Peshansky added a comment -

          (a) This is a conversion, not a coercion.
          (b) UByte can be coerced (through an implicit coercion operator) to Byte, which can then be converted to Int. The typechecker ought to find this converter chain.

          Show
          Igor Peshansky added a comment - (a) This is a conversion, not a coercion. (b) UByte can be coerced (through an implicit coercion operator) to Byte , which can then be converted to Int . The typechecker ought to find this converter chain.
          Hide
          David Grove added a comment -

          defer all non-critical X10 issues to 2.1.0.

          Show
          David Grove added a comment - defer all non-critical X10 issues to 2.1.0.
          Hide
          Igor Peshansky added a comment -

          Bulk defer all non-critical, non-blocker frontend issues to 2.1.0.

          Show
          Igor Peshansky added a comment - Bulk defer all non-critical, non-blocker frontend issues to 2.1.0.
          Hide
          David Grove added a comment -

          bulk defer of unresolved 2.1.0 bugs to 2.1.1.

          Show
          David Grove added a comment - bulk defer of unresolved 2.1.0 bugs to 2.1.1.
          Hide
          David Grove added a comment -

          bulk move of all unresolved issues from 2.1.1 to 2.1.2

          Show
          David Grove added a comment - bulk move of all unresolved issues from 2.1.1 to 2.1.2
          Hide
          David Grove added a comment -

          defer all non-critical 2.1.2 issues to 2.2.

          Show
          David Grove added a comment - defer all non-critical 2.1.2 issues to 2.2.
          Hide
          Igor Peshansky added a comment -

          Actually, according to XTENLANG-2508, there has to be an exact coercion, or the compiler does not find it. So we need to define coercions and conversions between all pairs of "primitive" numeric types.
          My suggestion is:

          from \ to Byte UByte Short UShort Int UInt Long ULong Float Double
          Byte   expl impl impl impl impl impl impl impl impl
          UByte expl   impl impl impl impl impl impl impl impl
          Short expl expl   expl impl impl impl impl impl impl
          UShort expl expl expl   impl impl impl impl impl impl
          Int expl expl expl expl   expl impl impl impl impl
          UInt expl expl expl expl expl   impl impl impl impl
          Long expl expl expl expl expl expl   expl impl impl
          ULong expl expl expl expl expl expl expl   impl impl
          Float expl expl expl expl expl expl expl expl   impl
          Double expl expl expl expl expl expl expl expl expl  

          The above reflects what Java does (modulo unsigned types). The implicit values in italics mean that the conversion may result in loss of precision, so we may consider making them explicit instead.

          Most of these are already defined in the libraries, but some are missing, as this issue shows.

          Show
          Igor Peshansky added a comment - Actually, according to XTENLANG-2508 , there has to be an exact coercion, or the compiler does not find it. So we need to define coercions and conversions between all pairs of "primitive" numeric types. My suggestion is: from \ to Byte UByte Short UShort Int UInt Long ULong Float Double Byte   expl impl impl impl impl impl impl impl impl UByte expl   impl impl impl impl impl impl impl impl Short expl expl   expl impl impl impl impl impl impl UShort expl expl expl   impl impl impl impl impl impl Int expl expl expl expl   expl impl impl impl impl UInt expl expl expl expl expl   impl impl impl impl Long expl expl expl expl expl expl   expl impl impl ULong expl expl expl expl expl expl expl   impl impl Float expl expl expl expl expl expl expl expl   impl Double expl expl expl expl expl expl expl expl expl   The above reflects what Java does (modulo unsigned types). The implicit values in italics mean that the conversion may result in loss of precision, so we may consider making them explicit instead. Most of these are already defined in the libraries, but some are missing, as this issue shows.
          Hide
          David Grove added a comment -

          might already be fixed, but should be nailed down once and for all in 2.2.

          Show
          David Grove added a comment - might already be fixed, but should be nailed down once and for all in 2.2.
          Hide
          Igor Peshansky added a comment -

          This will reject some correct programs, but will not accept incorrect ones, so it can be fixed after 2.2 in a backward-compatible way. Besides, it's a class library issue, not a frontend one.

          Show
          Igor Peshansky added a comment - This will reject some correct programs, but will not accept incorrect ones, so it can be fixed after 2.2 in a backward-compatible way. Besides, it's a class library issue, not a frontend one.
          Hide
          David Grove added a comment -

          Igor says it can be deferred, so deferring.

          Show
          David Grove added a comment - Igor says it can be deferred, so deferring.
          Hide
          David Grove added a comment -

          bulk defer of open issues to 2.2.2.

          Show
          David Grove added a comment - bulk defer of open issues to 2.2.2.
          Hide
          David Grove added a comment -

          bulk defer of issues to 2.2.3.

          Show
          David Grove added a comment - bulk defer of issues to 2.2.3.
          Hide
          Josh Milthorpe added a comment - - edited

          The attached patch adds a couple of missing coercions from unsigned to larger signed types. As the type converter is not finding the chains as suggested by Igor (e.g. UByte->Short->Int) it is necessary to add a separate operator for each allowable coercion. The patch also corrects the X10Doc for a couple of operators that were labelled as coercions but are actually conversions.

          Show
          Josh Milthorpe added a comment - - edited The attached patch adds a couple of missing coercions from unsigned to larger signed types. As the type converter is not finding the chains as suggested by Igor (e.g. UByte->Short->Int) it is necessary to add a separate operator for each allowable coercion. The patch also corrects the X10Doc for a couple of operators that were labelled as coercions but are actually conversions.
          Hide
          David Grove added a comment -

          commited patch in 23801.

          Closing this issue; any additional missing cases will be handled via new issues for specific missing methods in the class library.

          Show
          David Grove added a comment - commited patch in 23801. Closing this issue; any additional missing cases will be handled via new issues for specific missing methods in the class library.
          Hide
          David Grove added a comment -

          bulk close of issues as part of making 2.2.3 release notes.

          Show
          David Grove added a comment - bulk close of issues as part of making 2.2.3 release notes.

            People

            • Assignee:
              David Grove
              Reporter:
              Bard Bloom
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: