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

Abstract def overload with free var #14451

Open
Blacksmoke16 opened this issue Apr 7, 2024 · 2 comments
Open

Abstract def overload with free var #14451

Blacksmoke16 opened this issue Apr 7, 2024 · 2 comments

Comments

@Blacksmoke16
Copy link
Member

Blacksmoke16 commented Apr 7, 2024

Given the following code:

class Foo; end
 
module TestInterface
  abstract def add(foo : Foo) : Foo
  abstract def add(bar : T) : Nil forall T
end
 
class Test
  include TestInterface
  
  def add(foo : Foo) : Foo
    foo
  end
  
  def add(bar : T) : Nil forall T
    
  end
end
 
t = Test.new
 
pp t.add Foo.new
pp t.add 123

It fails to compile due to:

 11 | def add(foo : Foo) : Foo
                           ^--
Error: this method must return Nil, which is the return type of the overridden method TestInterface#add(bar : T) forall T, or a subtype of it, not Foo

I also tried with -Dpreview_overload_order which resulted in the same error.

It seems the abstract def checker thinks the overload with the explicit type is overriding the free var overload, instead of treating them separately.

I was able to work around this for now by defining the free var method in the interface as:

def add(bar : T) : Nil forall T
  {% @type.raise "abstract `def TestInterface#add(bar : T) : Nil forall T` must be implemented by #{@type}" %}
end

Which works for now 🤷.

@HertzDevil
Copy link
Contributor

Duplicate of #10699?

@Blacksmoke16
Copy link
Member Author

I found that one, but the error in this one was different so reported it separately.

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