https://play.crystal-lang.org/#/r/8hb8
require "json"
class Parent
def initialize(@data : String? = ""); end
end
class Child < Parent
def initialize(data : _, convert : Bool = false)
super convert ? data.to_json : data
end
end
pp Child.new 17
Module validation failed: Call parameter type does not match function signature!
%16 = load %String, %String* %15, !dbg !12
%String* %17 = call %String* @"*Child@Parent#initialize<String>:String"(%Child* %self, %String %16), !dbg !15
(Exception)
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from main
from __libc_start_main
from _start
from ???
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
_Originally posted by @Blacksmoke16 in https://github.com/crystal-lang/crystal/issues/7279#issuecomment-580528807_
Reduced:
class Parent
def initialize(@data : String)
end
end
class Child < Parent
def initialize
super("" || 1)
end
end
Child.new
Ah you were faster.
Trying to reduce I found the maybe related
class Parent
def initialize(@data : Int32? = 0); end
end
class Child < Parent
def initialize(data : _, convert : Bool = false)
super convert ? data.unsafe_as(Int64) : data
end
end
Child.new 17
Module validation failed: Load operand must be a pointer.
load void, i32 %15, !dbg !12
Call parameter type does not match function signature!
load void, i32 %15, !dbg !12
i32 %16 = call i32 @"*Child@Parent#initialize<Int32>:Int32"(%Child* %self, void <badref>), !dbg !15
i have the same error message, but with very different code:
Module validation failed: Call parameter type does not match function signature!
%5 = load %String, %String* %4, !dbg !14
%String* call void @"*Crlox::Return@Exception#initialize<(String | Nil)>:Nil"(%"Crlox::Return"* %self, %String %5), !dbg !15
(Exception)
from raise<Exception>:NoReturn
from raise<String>:NoReturn
from Crystal::CodeGenVisitor#finish:Nil
from Crystal::Compiler#codegen<Crystal::Program, Crystal::ASTNode+, Array(Crystal::Compiler::Source), String>:(Tuple(Array(Crystal::Compiler::CompilationUnit), Array(String)) | Nil)
from Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result
from Crystal::Command#run_command<Bool>:Nil
from Crystal::Command#run:(Bool | Nil)
from __crystal_main
from main
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
full source code to reproduce.
and the last change i made was in to add Callable in interpreter.cr on the Return class:
+ @value : (LiteralType | Callable)
+
+ def initialize(value : (LiteralType | Callable))
fixed by calling super() instead of super in the initializer