这是indexloc提供的服务,不要输入任何密码
Skip to content

Generic parameter when copying a trait method into an object that has a generic parameter of the same name #4463

@tetotechy

Description

@tetotechy

This code won't compile:

actor Main
  new create(env: Env) =>
    env.out.print("Hello")
    
trait Foo[In, Out]
  fun apply(src: In^): Out^
  
  fun ref into[Into](from: {(Out^): Into^}): Foo[In, Into] =>
    Converter[In, Out, Into](this, from)
    
primitive Converter[In, Out, Into]
  fun apply(foo: Foo[In, Out], from: {(Out^): Into^}): Foo[In, Into] =>
    object is Foo[In, Into]
      fun apply(src: In^): Into^ =>
        from(foo(src))
    end

(The reason I am using a Converter primitive and not directly an object literal is #4451)

But this will do, just changing the name of the Into type (and only that) into any other name (here, Dest):

actor Main
  new create(env: Env) =>
    env.out.print("Hello")
    
trait Foo[In, Out]
  fun apply(src: In^): Out^
  
  fun ref into[Into](from: {(Out^): Into^}): Foo[In, Into] =>
    Converter[In, Out, Into](this, from)
    
primitive Converter[In, Out, Dest]
  fun apply(foo: Foo[In, Out], from: {(Out^): Dest^}): Foo[In, Dest] =>
    object is Foo[In, Dest]
      fun apply(src: In^): Dest^ =>
        from(foo(src))
    end

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions