Crystal: Unable to call class method from extended module in generic class

Created on 23 Sep 2017  路  4Comments  路  Source: crystal-lang/crystal

module Foo(T)
  def foo
    p "class foo: #{T}"
  end
end

class A(T)
  extend Foo(T)
end

A.foo        # OK
A(Int32).foo # Error
module Foo
  def foo
    p "class foo"
  end
end

class A(T)
  extend Foo
end

A.foo        # OK
A(Int32).foo # Error

Raises Error in temp.cr:11: undefined method 'foo' for A(Int32):Class in both cases.

May be a duplicate, but I haven't found any.

bug compiler

All 4 comments

I can reproduce this,

Also

class A(T)
  class_getter a = 0
end

A(Int32).a

Outputs:

cast from Crystal::GenericClassInstanceType to Crystal::ClassVarContainer failed,
at /build/crystal/src/crystal-0.23.1/src/compiler/crystal/semantic/semantic_visitor.cr:454:5:454
0x5580eb7f4045: ??? at ??
0x5580ebbed00a: ??? at ??
0x5580ebb849f8: ??? at ??
0x5580ec231c3e: ??? at ??
0x5580ec22bfc5: ??? at ??
0x5580eb83209d: ??? at ??
0x5580ebc29cad: ??? at ??
0x5580ebb848da: ??? at ??
0x5580ebb86a71: ??? at ??
0x5580ebeb9099: ??? at ??
0x5580ebddceed: ??? at ??
0x5580ec24a683: ??? at ??
0x5580eb82b9e0: ??? at ??
0x5580eb7fbb9c: main at ??
0x7fe1706274ca: __libc_start_main at ??
0x5580eb7d4c7a: _start at ??
0x0: ??? at ??
Error: you've found a bug in the Crystal compiler.
Please open an issue, including source code that will allow us to reproduce the bug:
https://github.com/crystal-lang/crystal/issues

@faustinoaq it looks like an easter egg 馃槃

@vladfaust Both cases seem to be fixed now. Can you confirm please?

Checked in Crystal 0.31.1 on MacOS

$ crystal --version
Crystal 0.31.1 (2019-10-02)

LLVM: 8.0.1
Default target: x86_64-apple-macosx

Result 1

$ crystal test.cr
"class foo: T"
"class foo: Int32"

Result 2

$ crystal test.cr
"class foo"
"class foo"

Indeed, I remember doing some fixes related to modules and generic types.

And this was reported on 2017? Ugh, time flies! 馃槰

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RX14 picture RX14  路  62Comments

MakeNowJust picture MakeNowJust  路  64Comments

ezrast picture ezrast  路  84Comments

akzhan picture akzhan  路  67Comments

asterite picture asterite  路  70Comments