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

Constrained monomorph vs const struct #9597

Closed
kLabz opened this issue Jun 16, 2020 · 2 comments
Closed

Constrained monomorph vs const struct #9597

kLabz opened this issue Jun 16, 2020 · 2 comments

Comments

@kLabz
Copy link
Contributor

kLabz commented Jun 16, 2020

class Test4 {
  static function main() {
    var data = [
      {name: 'Page A', uv: 4000, pv: 2400, amt: 2400},
      {name: 'Page B', uv: 3000, pv: 1398, amt: 2210},
      {name: 'Page C', uv: -1000, pv: 9800, amt: 2290},
      {name: 'Page D', uv: 500, pv: 3908, amt: 2000},
      {name: 'Page E', uv: -2000, pv: 4800, amt: 2181},
      {name: 'Page F', uv: -250, pv: 3800, amt: 2500},
      {name: 'Page G', uv: 3490, pv: 4300, amt: 2100}
    ];

    foo(data);
  }

  static function foo<T:{uv:Int}>(data:Array<T>):Void {}
}

/*
  Test4.hx:13: characters 7-11 : error: { uv : Int, pv : Int, name : String, amt : Int } has extra field amt
  Test4.hx:13: characters 7-11 :  have: Array<{ uv, pv, name, amt }>
  Test4.hx:13: characters 7-11 :  want: Array<{ uv }>
  Test4.hx:13: characters 7-11 : For function argument 'data'
*/
@Simn
Copy link
Member

Simn commented Jun 16, 2020

This is a variant of #3192. It used to work just because constraints checks were delayed until after the Const flag was removed via ctx.opened in type_function. With the checks being done earlier now, the flag is still set by the time we unify.

@kLabz
Copy link
Contributor Author

kLabz commented Jun 16, 2020

Workaround:

static function foo<TBase:{uv:Int}, T:TBase>(data:Array<T>):Void {}

Simn added a commit that referenced this issue Jun 16, 2020
@Simn Simn closed this as completed in 908c4d6 Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants