bugKawa - Bugs: bug #36853, Propagate type parameters

 
 

bug #36853: Propagate type parameters

Submitter:  Helmut Eller <ellerh>
Submitted:  Mon 16 Jul 2012 03:12:07 PM UTC
   
 
Category:  Type declaration and inference Severity:  3 - Normal
Item Group:  Feature Request Status:  Fixed
Privacy:  Public Assigned to:  bothner
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 17 Jul 2012 07:48:06 PM UTC, comment #5: 

The problem in the example in comment #4 doesn't seem to be related to type parameters.  Note there are no warnings if the function f is inlined.

The problem is that call to f first "validates" (type-checks) the function (i.e. the lambda) before validating the arguments. Usually, that's what you want, so you can type-check the actual argument using the specified type of the formal parameter. But if the formal parameter does't have type specifier, then you'd like to validate the actual argument, and infer the parameter type from that.  In principle this shouldn't be too hard, at least when there is only a single call site, but re-factoring the code to support that looks tricky.  Another complication is that the same pass also check things like if a variable is initialized, which makes doing things in the right order even more difficult.

Per Bothner <bothner>
Group administrator
Tue 17 Jul 2012 11:23:18 AM UTC, comment #4: 

Here's a variation that still has problems:

(define (foo (l java.util.List[String]))
  (let ((f (lambda (s) (s:intern))))
    (f (l:get 0))))


Helmut Eller <ellerh>
Tue 17 Jul 2012 08:09:29 AM UTC, comment #3: 

I was thinking more in the line of:
  class Foo<E extends java.util.List> ...

... Foo[vector] ...

I.e. using super or extends.

Your example doesn't report any warnings when I tried it.  Perhaps because it (as far as I can tell) doesn't use wildcards.

Having wildcard work is probably not a priority.

Per Bothner <bothner>
Group administrator
Tue 17 Jul 2012 07:57:15 AM UTC, comment #2: 


>The code doesn't support wildcards yet. Perhaps you could come
>with some testcases using wildcards?


You mean something like this?

(define (map->alist (m java.util.Map))
  (let* ((entries (m:entrySet))
         (iter (entries:iterator)))
    (let loop ((alist '()))
      (if (iter:hasNext)
          (let ((entry (iter:next)))
            (loop (cons (cons (entry:getKey) (entry:getValue))
                        alist)))
          alist))))

(equal? (map->alist (java.util.Collections:singletonMap 'a 1))
        '((a . 1)))


Helmut Eller <ellerh>
Tue 17 Jul 2012 06:48:44 AM UTC, comment #1: 

I checked in a fix for this, as well as your test case.

The code doesn't support wildcards yet.  Perhaps you could come up with some testcases using wildcards?

Per Bothner <bothner>
Group administrator
Mon 16 Jul 2012 03:12:07 PM UTC, original submission:  

This example:

(define (my-member (key String) (strings java.util.List[String]))
  (let ((iter (strings:iterator)))
    (let loop ()
      (if (iter:hasNext)
          (let ((next (iter:next)))
            (if (eq? (next:intern) key)
                #t
                (loop)))
          #f))))


generates this warning:

x.scm:7:15: warning - no known slot 'intern' in java.lang.Object


It would be nice if the compiler would automatically infer that the
type of iter is Iterator[String] and consequently the type of next is
String.

Helmut Eller <ellerh>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bothner (Posted a comment)
  • -email is unavailable- added by ellerh (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-07-17 bothner StatusNone Fixed
        Assigned toNone bothner

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code