Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type error in parametrized interface. #1875

Open
ghost opened this issue Apr 29, 2017 · 4 comments · May be fixed by #3664
Open

Type error in parametrized interface. #1875

ghost opened this issue Apr 29, 2017 · 4 comments · May be fixed by #3664
Labels
bug Something isn't working needs investigation This needs to be looked into before its "ready for work"

Comments

@ghost
Copy link

ghost commented Apr 29, 2017

The following setup:

interface State[S, I, O]
    fun val apply(state: S, input: I): (S, O)
    fun val bind[O2](next: State[S, O, O2]): State[S, I, O2]

doesn't typecheck. The compiler complains that

type argument is outside its constraint
argument: O #any
constraint: O2 #any
O #any is not a subtype of O2

Aliasing O to some other name or replacing it with any of the other types in the bind definition makes it compile.

I'm running ponyc v0.13.1 on Arch Linux.

@SeanTAllen
Copy link
Member

@ponylang/committer see: https://pony.groups.io/g/user/message/1077

@plietar
Copy link
Contributor

plietar commented Apr 29, 2017

I had a look into this, with a slightly reduced test case :

class A
interface State[X, Y]
   fun val bind(next: State[Y, A ref])

The unconstrained type params are actually constraint by themselves, so the constraints are X: X, Y: Y.

The loop in reify reifies the constraint by replacing each type variable by its value, in order. It first replaced X by Y, and THEN replaced Y by A ref. So the constraint goes from (X, Y) to (Y, Y) to (A ref, A ref). The problem comes from the fact that the reification is not "atomic". We'd want to simultaneously replace all type variables.

It then checks is_subtype_constraint((Y, A ref), (A ref, A ref)), which fails with

Y #any is not a subtype of A ref: the subtype has no constraint

@SeanTAllen
Copy link
Member

nice triaging @plietar

@jemc
Copy link
Member

jemc commented May 2, 2017

Based on that triaging, I'm marking as difficulty: hard.

plietar added a commit to plietar/ponyc that referenced this issue May 4, 2017
mfelsche pushed a commit to plietar/ponyc that referenced this issue Oct 9, 2018
@SeanTAllen SeanTAllen added needs investigation This needs to be looked into before its "ready for work" bug Something isn't working and removed bug: 1 - needs investigation labels May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs investigation This needs to be looked into before its "ready for work"
Projects
None yet
3 participants