Last active
October 21, 2018 19:30
-
-
Save ljuti/d719507523f6c9fc8725672b893b0951 to your computer and use it in GitHub Desktop.
Code to reproduce an upcasting compiler bug with Crystal 0.26.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module A | |
abstract struct BaseFactory | |
alias ValidContextTypes = A::Context | |
def initialize(@context : ValidContextTypes) | |
end | |
end | |
end | |
module A | |
struct Config | |
alias Number = Float64 | Int64 | Int32 | |
alias AcceptedTypes = String.class | Number.class | Nil | |
alias AcceptedFactories = BaseFactory.class | ::DummyFactory.class | |
def initialize(@given_type : AcceptedTypes, @given_factory : AcceptedFactories) | |
end | |
def initialize_factory(context) | |
@given_factory.new(context) | |
end | |
end | |
end | |
module A | |
struct Context | |
def input | |
A::Value.new | |
end | |
end | |
end | |
module A | |
struct Value | |
def raw | |
"raw" | |
end | |
end | |
end | |
require "spec" | |
struct ::DummyFactory < A::BaseFactory | |
end | |
describe A::Config do | |
describe "Initialization" do | |
it "can instantiate a FieldConfig" do | |
klass = A::Config.new(given_type: String, given_factory: ::DummyFactory) | |
klass.should be_a(A::Config) | |
end | |
end | |
describe "#initialize_factory(context)" do | |
it "initializes a factory with given context" do | |
ctx = A::Context.new | |
klass = A::Config.new(given_type: String, given_factory: ::DummyFactory).initialize_factory(ctx) | |
klass.should be_a(DummyFactory) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ljuti@Vanquish ~/Code/playground/crystal/upcasting $ crystal spec/upcasting_spec.cr | |
BUG: trying to upcast DummyFactory <- A::BaseFactory (Exception) | |
from Crystal::CodeGenVisitor#upcast_distinct<LLVM::Value, Crystal::Type+, Crystal::Type+>:NoReturn | |
from Crystal::CodeGenVisitor#upcast<LLVM::Value, Crystal::VirtualType, Crystal::Type+>:LLVM::Value | |
from Crystal::CodeGenVisitor#codegen_primitive<Crystal::Call, Crystal::Primitive+, Crystal::Def+, Array(LLVM::Value)>:LLVM::Value | |
from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool | |
from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil) | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function | |
from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function | |
from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function | |
from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function | |
from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil) | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil | |
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>: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 | Crystal::Compiler::Result | Nil) | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment