Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

unsoundness with generic method with enumerated bound #4566

Closed
CeylonMigrationBot opened this issue Nov 3, 2015 · 1 comment
Closed

unsoundness with generic method with enumerated bound #4566

CeylonMigrationBot opened this issue Nov 3, 2015 · 1 comment

Comments

@CeylonMigrationBot
Copy link

[@gavinking] As seen here, the following code should be rejected by the typechecker:

class Lizt<out Item>() {

    value list = ArrayList<Item>();

    shared Item add<in InItem>(InItem i) 
            given InItem of Item { 
        list.add(i of Item);
        return i of Item; 
    }
}

class Person() {}
class Customer() extends Person(){}

shared void run2() {
    Lizt<Person> people = Lizt<Customer>();
    people.add<Person>(Person()); //Oops!!
}

The enumerated bound is a contravariant location!

Note that we do do the right check for upper bounds.

[Migrated from ceylon/ceylon-spec#1460]

@gavinking
Copy link
Contributor

Fixed.

gavinking added a commit that referenced this issue Dec 1, 2015
gavinking added a commit that referenced this issue Dec 1, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants