X10
  1. X10
  2. XTENLANG-2541

Constraints on type parameters in method formals aren't added to the environment used to typecheck the method body

    Details

    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      Compiling

      import x10.util.Ordered;
      public class LessIsMore{
         static def doIt[T](a: T{T <: Ordered[T]}) {
            return a < a;
         }
      }
      

      yields

      LessIsMore.x10:4: No valid method call found for call in given type.    
           	 Call: operator<(T, T)    
           	 Type: x10.lang.Any
      

      Can you explain what this error message means? I thought that T<:Ordered[T] meant "T implements Ordered[T]"
      and therefore (since "<" is in that interface) I ought to be able to use it.

        Activity

        Hide
        Igor Peshansky added a comment -

        This is a bug in propagating type constraints from method arguments into the environment. A workaround for now is to move the type constraint into the method guard, namely:

        import x10.util.Ordered;
        public class LessIsMore {
          static def doIt[T](a: T){T <: Ordered[T]} {
            return a < a;
          }
        }
        
        Show
        Igor Peshansky added a comment - This is a bug in propagating type constraints from method arguments into the environment. A workaround for now is to move the type constraint into the method guard, namely: import x10.util.Ordered; public class LessIsMore { static def doIt[T](a: T){T <: Ordered[T]} { return a < a; } }
        Igor Peshansky made changes -
        Field Original Value New Value
        Fix Version/s X10 2.2 [ 16002 ]
        Affects Version/s X10 2.1.2 [ 16498 ]
        Component/s X10 Compiler: Front-end Constraints [ 14507 ]
        Component/s X10 Compiler: Front-end [ 13471 ]
        Hide
        Jonathan Brezin added a comment -

        Thanks. It does work in my "real" code. It occurred to me that there is a situation where you really might want to attach the constraint to the argument.

        def doIt[T]{a:T{T <: Ordered[T]}, b: T) { /* need "a" ordered, but not b */ }
        

        Not all subtypes of T need implement Ordered[T], but it may be important that the first argument should. So it does make sense to put some effort into fixing the constraint propagation.

        Show
        Jonathan Brezin added a comment - Thanks. It does work in my "real" code. It occurred to me that there is a situation where you really might want to attach the constraint to the argument. def doIt[T]{a:T{T <: Ordered[T]}, b: T) { /* need "a" ordered, but not b */ } Not all subtypes of T need implement Ordered [T] , but it may be important that the first argument should. So it does make sense to put some effort into fixing the constraint propagation.
        Hide
        Igor Peshansky added a comment -

        Sorry, it doesn't work that way. You are not constraining a and b, you are constraining T. And the constraint is in effect for the whole method. So either both a and b are ordered, or neither is (because they are the same type, T). Since T is defined by doIt(), you may as well put the constraint into the method guard.

        If you want two potentially different types, you have to use two different type variables.

        The meaning you tried to assign to this idiom above is actually captured by XTENLANG-683.

        Show
        Igor Peshansky added a comment - Sorry, it doesn't work that way. You are not constraining a and b , you are constraining T . And the constraint is in effect for the whole method. So either both a and b are ordered, or neither is (because they are the same type, T ). Since T is defined by doIt() , you may as well put the constraint into the method guard. If you want two potentially different types, you have to use two different type variables. The meaning you tried to assign to this idiom above is actually captured by XTENLANG-683 .
        Hide
        Jonathan Brezin added a comment -

        Again thanks: I'll make sure I explain this clearly in the Guide.

        Show
        Jonathan Brezin added a comment - Again thanks: I'll make sure I explain this clearly in the Guide.
        Igor Peshansky made changes -
        Link This issue is depended upon by XTENLANG-2584 [ XTENLANG-2584 ]
        Hide
        Igor Peshansky added a comment -

        Defer to 2.2.1.

        Show
        Igor Peshansky added a comment - Defer to 2.2.1.
        Igor Peshansky made changes -
        Fix Version/s X10 2.2.1 [ 17131 ]
        Fix Version/s X10 2.2 [ 16002 ]
        Igor Peshansky made changes -
        Link This issue is depended upon by XTENLANG-2584 [ XTENLANG-2584 ]
        David Grove made changes -
        Summary What does Ordered interface mean? Another strange error message Constraints on type parameters in method guards aren't added to the environment used to typecheck the method body
        David Grove made changes -
        Summary Constraints on type parameters in method guards aren't added to the environment used to typecheck the method body Constraints on type parameters in method formals aren't added to the environment used to typecheck the method body
        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.
        David Grove made changes -
        Fix Version/s X10 2.2.2 [ 17639 ]
        Fix Version/s X10 2.2.1 [ 17131 ]
        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.
        David Grove made changes -
        Fix Version/s X10 2.2.3 [ 18146 ]
        Fix Version/s X10 2.2.2 [ 17639 ]
        David Grove made changes -
        Assignee Igor Peshansky [ ipeshansky ]
        David Grove made changes -
        Fix Version/s X10 2.3 [ 17009 ]
        Fix Version/s X10 2.2.3 [ 18146 ]
        Hide
        David Grove added a comment -

        bulk defer of 2.3.0 open issues to 2.3.1.

        Show
        David Grove added a comment - bulk defer of 2.3.0 open issues to 2.3.1.
        David Grove made changes -
        Fix Version/s X10 2.3.1 [ 18657 ]
        Fix Version/s X10 2.3 [ 17009 ]
        Hide
        David Grove added a comment -

        bulk defer to 2.3.2

        Show
        David Grove added a comment - bulk defer to 2.3.2
        David Grove made changes -
        Fix Version/s X10 2.3.2 [ 19010 ]
        Fix Version/s X10 2.3.1 [ 18657 ]
        Hide
        David Grove added a comment -

        bulk defer to 2.4.1.

        Show
        David Grove added a comment - bulk defer to 2.4.1.
        David Grove made changes -
        Fix Version/s X10 2.4.1 [ 19142 ]
        Fix Version/s X10 2.3.2 [ 19010 ]
        Hide
        David Grove added a comment -

        bulk defer to 2.4.2

        Show
        David Grove added a comment - bulk defer to 2.4.2
        David Grove made changes -
        Fix Version/s X10 2.4.2 [ 19827 ]
        Fix Version/s X10 2.4.1 [ 19142 ]
        Hide
        David Grove added a comment -

        bulk defer to 2.4.3

        Show
        David Grove added a comment - bulk defer to 2.4.3
        David Grove made changes -
        Fix Version/s X10 2.4.2 [ 19827 ]
        Fix Version/s X10 2.4.3 [ 20024 ]
        Hide
        David Grove added a comment -

        bulk defer to 2.4.4

        Show
        David Grove added a comment - bulk defer to 2.4.4
        David Grove made changes -
        Fix Version/s X10 2.4.3 [ 20024 ]
        Fix Version/s X10 2.4.4 [ 20386 ]
        David Grove made changes -
        Fix Version/s X10 2.4.4 [ 20386 ]
        Fix Version/s X10 2.5.1 [ 20503 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Jonathan Brezin
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: