X10
  1. X10
  2. XTENLANG-55

"incompatible types" using the next() function of an Iterator

    Details

    • Number of attachments :
      0

      Description

      class C {}
      
      class Bug {
      
          def foo(it:Iterator[C]) {
              val c:C = it.next();
          }
      }
      

      x10c: classes\Bug.java:90: incompatible types
      found : java.lang.Object
      required: C
      /* } */).next();
      ^
      1 error

      Workaround: use for (...) syntax where possible; if not possible add a cast: it.next() as C.

        Activity

        Bruce Lucas made changes -
        Field Original Value New Value
        Summary handling of Iterator is broken "incompatible types" using the next() function of an Iterator
        Priority Blocker [ 1 ] Major [ 3 ]
        Description {code}
        class C {}

        class Bug {

            def foo(it:Iterator[C]) {
                val c:C = it.next();
            }
        }
        {code}
        x10c: classes\Bug.java:90: incompatible types
             found : java.lang.Object
             required: C
             /* } */).next();
             ^
             1 error

        If we change the definition of x10.lang.Iterator to not have a NativeRep of java.util.Iterator the preceding code works, but I imagine this would break X10 library code written in Java that implements Iterators, and then also the following code breaks:
        \\
        \\
        {code}
        class C {}

        class D {
            incomplete def iterator(): Iterator[C];
        }

        class Bug {

            def bar(d:D) {
                for (c:C in d);
            }

        }
        {code}


        x10c: classes\Bug.java:82: incompatible types
             found : x10.lang.Iterator<capture of ? extends C>
             required: java.util.Iterator
             for (java.util.Iterator c__ = (d).iterator(); c__.hasNext(); ) {
             ^
             Note: Some input files use unchecked or unsafe operations.
             Note: Recompile with -Xlint:unchecked for details.
             1 error

        {code}
        class C {}

        class Bug {

            def foo(it:Iterator[C]) {
                val c:C = it.next();
            }
        }
        {code}
        x10c: classes\Bug.java:90: incompatible types
             found : java.lang.Object
             required: C
             /* } */).next();
             ^
             1 error

        Workaround: use for (...) syntax where possible; if not possible add a cast: it.next() as C.
        Hide
        Bruce Lucas added a comment -

        Appears to have been fixed (per daily test run)

        Show
        Bruce Lucas added a comment - Appears to have been fixed (per daily test run)
        Bruce Lucas made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Closed [ 6 ]

          People

          • Assignee:
            Nate Nystrom
            Reporter:
            Bruce Lucas
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: