[ nice-Bugs-1672222 ] Abstract interfaces and covariant return types

"SourceForge.net" <[email protected]> Thu, 01 Mar 2007 23:28:53 -0800
Newsgroups gmane.comp.lang.nice.devel
Message-ID <[email protected]>
Bugs item #1672222, was opened at 2007-03-02 06:45
Message generated for change (Comment added) made by drmaciver
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=112788&aid=1672222&group_id=12788

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: David R. MacIver (drmaciver)
Assigned to: Nobody/Anonymous (nobody)
Summary: Abstract interfaces and covariant return types

Initial Comment:
Code:

package test;
import nice.functional;

class Test implements Foo 
{
    Test[] children;
}

more(Test t) = generator(t.children);

abstract interface Foo 
{
}

<Foo T> () -> T more(T t); 

Compiler error:

Incorrect return type:
Found   : ()->test.Test
Expected: ()->T

This appears not to always fail. For example if I replace the implementation with 

more(Test t) = () => t;

The code compiles fine.

I've not been able to narrow down exactly what circumstances it fails in.

----------------------------------------------------------------------

>Comment By: David R. MacIver (drmaciver)
Date: 2007-03-02 07:28

Message:
Logged In: YES 
user_id=1681313
Originator: YES

Ok. It's not a bug - it's just a somewhat unhelpful error message and a
slightly confusing feature.

The problem is of course that if I subclass Test, say Test2 extends Test,
then the type parameter will be incorrect as more(Test2) will return a ()
=> Test, so the method would need overriding (I'm not sure why the compiler
doesn't just force you to override the method, but maybe there's some good
reason for it). If we say "Test finally implements Foo" then this forces
the type parameter T to never be bound below Test, so the problem doesn't
come up. 

----------------------------------------------------------------------

Comment By: David R. MacIver (drmaciver)
Date: 2007-03-02 06:56

Message:
Logged In: YES 
user_id=1681313
Originator: YES

As pointed out by arjanb in #nice, if you replace 'implements Foo' with
'finally implements Foo', this starts working. I still think it's a bug
though. :-)

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=112788&aid=1672222&group_id=12788

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV