Skip to content

Virtual dispatch failure when class includes multiple modules #15913

Open
@HertzDevil

Description

@HertzDevil

All of the following should print 1, regardless of whether the receiver or the argument is virtual:

abstract class Node; end

class ArrayNode < Node; end

class StringNode < Node; end

module ArrayLikePredicate
  def foo(x : ArrayNode)
    1
  end
end

module StringLikePredicate
  def foo(x : StringNode)
    2
  end
end

abstract class Foo
  def foo(x)
    3
  end
end

class Bar < Foo
  include ArrayLikePredicate
  include StringLikePredicate
end

Bar.new.foo(ArrayNode.new)                  # => 1
Bar.new.foo(ArrayNode.new.as(Node))         # => 1
Bar.new.as(Foo).foo(ArrayNode.new)          # => 1
Bar.new.as(Foo).foo(ArrayNode.new.as(Node)) # => 3

This is not a regression as I could replicate the same on very old compilers like 1.0. It is affected by neither -Dpreview_overload_order nor #11840, and the interpreter has the same issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:bugA bug in the code. Does not apply to documentation, specs, etc.topic:compiler:semantic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions