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

Generic modules: is_a? returns incorrect value #4287

Closed
Ragmaanir opened this issue Apr 13, 2017 · 4 comments · Fixed by #10519
Closed

Generic modules: is_a? returns incorrect value #4287

Ragmaanir opened this issue Apr 13, 2017 · 4 comments · Fixed by #10519
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic topic:compiler

Comments

@Ragmaanir
Copy link

https://carc.in/#/r/1uz9

module A
end

module B(T)
  include A
end

class C
  include B(Int32)
end

class D
  getter c : A
  
  def initialize(@c : A)
  end
end

d = D.new(C.new)

puts d.c.is_a?(C) # => false
puts d.c.class == C # => true

crystal -v: Crystal 0.21.1 [3c6c75e] (2017-03-06) LLVM 3.5.0

Both expressions at the bottom should return true. Removing the type parameter lets it return the correct values. Is this related to #2665 ?

@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler labels Apr 16, 2017
@iSarCasm
Copy link
Contributor

iSarCasm commented Oct 16, 2017

Reduced
https://carc.in/#/r/2wvl

module B(T)
end

class C
  include B(Int32)
end

class D
  def initialize(c : B(Int32))
    puts c.is_a?(C)   # => true
    puts c.class == C # => true
    @c = c
    puts @c.is_a?(C)   # => false
    puts @c.class == C # => true
  end
end

D.new(C.new)

@asterite
Copy link
Member

Reduced:

module A
end

module B(T)
  include A
end

class C
  include B(Int32)
end

c = C.new.as(A)
p c.is_a?(C) # => false (but should be true)

@jbomanson
Copy link

I bumped into this bug myself recently using Crystal 0.23.1 [e2a1389] (2017-07-13) LLVM 3.8.1.

Reduced:

module B(T)
end

class C
  include B(Int32)
end

c = C.new.as(B(Int32))
p c.is_a?(C) # => false (but should be true)

@miketheman
Copy link
Contributor

#codetriage This still appears today with 0.26.1 https://carc.in/#/r/589h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic topic:compiler
Projects
None yet
5 participants