{"action":"created","issue":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/6684","repository_url":"https://api.github.com/repos/crystal-lang/crystal","labels_url":"https://api.github.com/repos/crystal-lang/crystal/issues/6684/labels{/name}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/issues/6684/comments","events_url":"https://api.github.com/repos/crystal-lang/crystal/issues/6684/events","html_url":"https://github.com/crystal-lang/crystal/issues/6684","id":358305733,"node_id":"MDU6SXNzdWUzNTgzMDU3MzM=","number":6684,"title":"Compile error - Invalid memory access  when compiling generic","user":{"login":"Meldanor","id":118621,"node_id":"MDQ6VXNlcjExODYyMQ==","avatar_url":"https://avatars2.githubusercontent.com/u/118621?v=4","gravatar_id":"","url":"https://api.github.com/users/Meldanor","html_url":"https://github.com/Meldanor","followers_url":"https://api.github.com/users/Meldanor/followers","following_url":"https://api.github.com/users/Meldanor/following{/other_user}","gists_url":"https://api.github.com/users/Meldanor/gists{/gist_id}","starred_url":"https://api.github.com/users/Meldanor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Meldanor/subscriptions","organizations_url":"https://api.github.com/users/Meldanor/orgs","repos_url":"https://api.github.com/users/Meldanor/repos","events_url":"https://api.github.com/users/Meldanor/events{/privacy}","received_events_url":"https://api.github.com/users/Meldanor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-08T15:40:32Z","updated_at":"2018-09-08T15:49:50Z","closed_at":null,"author_association":"NONE","body":"Problem:\r\n\r\nYou get an invalid memory adress error when compiling a generic and wants to access Type#name\r\n\r\nError (from my machine):\r\n```bash\r\nInvalid memory access (signal 11) at address 0x0\r\n[0x10d77cbb7] *CallStack::print_backtrace:Int32 +39\r\n[0x10ce72bfe] __crystal_sigfault_handler +46\r\n[0x7fff73e41f5a] _sigtramp +26\r\n[0x10e57f5ef] _ZN4llvm11PointerType3getEPNS_4TypeEj +21\r\n[0x10e1dcbff] _ZN4llvm17GetElementPtrInst16getGEPReturnTypeEPNS_4TypeEPNS_5ValueENS_8ArrayRefIS4_EE +63\r\n[0x10e183eaf] _ZN4llvm17GetElementPtrInst6CreateEPNS_4TypeEPNS_5ValueENS_8ArrayRefIS4_EERKNS_5TwineEPNS_11InstructionE +111\r\n[0x10dfad782] _ZN4llvm9IRBuilderINS_14ConstantFolderENS_24IRBuilderDefaultInserterEE17CreateInBoundsGEPEPNS_4TypeEPNS_5ValueENS_8ArrayRefIS7_EERKNS_5TwineE +114\r\n[0x10e502592] LLVMBuildInBoundsGEP +59\r\n[0x10d4e6eaa] *Crystal::CodeGenVisitor@Crystal::LLVMBuilderHelper#gep<LLVM::Value, Int32, Int32, String>:LLVM::Value +170\r\n[0x10d519bd0] *Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil) +1280\r\n[0x10d500811] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +1825\r\n[0x10d5008a9] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +1977\r\n[0x10d514f3c] *Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function +4444\r\n[0x10d517fdd] *Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function +2445\r\n[0x10d51f8ed] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +4525\r\n[0x10d5029be] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +10446\r\n[0x10d5008a9] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +1977\r\n[0x10d514f3c] *Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function +4444\r\n[0x10d517fdd] *Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function +2445\r\n[0x10d51f8ed] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +4525\r\n[0x10d5029be] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +10446\r\n[0x10d524204] *Crystal::CodeGenVisitor#prepare_call_args_non_external<Crystal::Call, Crystal::Def+, Crystal::Type+>:Tuple(Array(LLVM::Value), Bool) +1140\r\n[0x10d51f766] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +4134\r\n[0x10d5029be] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +10446\r\n[0x10d502d52] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +11362\r\n[0x10d5008a9] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +1977\r\n[0x10d502cf0] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +11264\r\n[0x10d5008a9] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +1977\r\n[0x10d5051d1] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +20705\r\n[0x10d514f3c] *Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function +4444\r\n[0x10d517fdd] *Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function +2445\r\n[0x10d51f8ed] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +4525\r\n[0x10d5029be] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +10446\r\n[0x10d523df8] *Crystal::CodeGenVisitor#prepare_call_args_non_external<Crystal::Call, Crystal::Def+, Crystal::Type+>:Tuple(Array(LLVM::Value), Bool) +104\r\n[0x10d51f766] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +4134\r\n[0x10d5029be] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +10446\r\n[0x10d524204] *Crystal::CodeGenVisitor#prepare_call_args_non_external<Crystal::Call, Crystal::Def+, Crystal::Type+>:Tuple(Array(LLVM::Value), Bool) +1140\r\n[0x10d51f766] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +4134\r\n[0x10d5029be] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +10446\r\n[0x10d5008a9] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +1977\r\n[0x10d502d52] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +11362\r\n[0x10d5008a9] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +1977\r\n[0x10d514f3c] *Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function +4444\r\n[0x10d5012a7] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +4535\r\n[0x10d519809] *Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil) +313\r\n[0x10d500811] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +1825\r\n[0x10d5008a9] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +1977\r\n[0x10d505b56] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +23142\r\n[0x10d520044] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +6404\r\n[0x10d5029be] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +10446\r\n[0x10d5008a9] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +1977\r\n[0x10d505b56] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +23142\r\n[0x10d520044] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +6404\r\n[0x10d5029be] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +10446\r\n[0x10d500c83] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +2963\r\n[0x10d5008a9] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +1977\r\n[0x10d4d234a] *Crystal::Compiler#codegen<Crystal::Program, Crystal::ASTNode+, Array(Crystal::Compiler::Source), String>:(Tuple(Array(Crystal::Compiler::CompilationUnit), Array(String)) | Nil) +490\r\n[0x10d6f8bc4] *Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result +116\r\n[0x10ce85e9d] *Crystal::Command#run:(Bool | Crystal::Compiler::Result | Nil) +845\r\n[0x10ce50bf4] main +212\r\n```\r\n\r\nError (from crystal-play):\r\n```bash\r\nInvalid memory access (signal 11) at address 0x0\r\n[0x56328dfca296] ???\r\n[0x56328d6d4c5a] __crystal_sigfault_handler +42\r\n[0x7fef38cfd3b0] ???\r\n[0x7fef39e71354] _ZN4llvm11PointerType3getEPNS_4TypeEj +20\r\n[0x7fef39dace1e] LLVMBuildInBoundsGEP +302\r\n[0x56328dd2cfba] ???\r\n[0x56328dd557c9] ???\r\n[0x56328dd61622] ???\r\n[0x56328dd47377] ???\r\n[0x56328dd4744b] ???\r\n[0x56328dd5c741] ???\r\n[0x56328dd5fba6] ???\r\n[0x56328dd6753e] ???\r\n[0x56328dd49853] ???\r\n[0x56328dd4744b] ???\r\n[0x56328dd5c741] ???\r\n[0x56328dd5fba6] ???\r\n[0x56328dd6753e] ???\r\n[0x56328dd49853] ???\r\n[0x56328dd4744b] ???\r\n[0x56328dd1763c] ???\r\n[0x56328df41ad3] ???\r\n[0x56328df9bf91] ???\r\n[0x56328d6ee3ad] ???\r\n[0x56328d6b69a7] __crystal_main +13591\r\n[0x56328d6ba726] main +198\r\n[0x7fef388ca003] __libc_start_main +243\r\n[0x56328d6b33be] _start +46\r\n[0x0] ???\r\n\r\n```\r\n\r\nExample code:\r\n```crystal\r\nclass ErrorResponse\r\n  def initialize(@statusCode : Int32)\r\n  end\r\n\r\n  def to_s(io)\r\n    io << \"Type: \" << self.class.name << \";\"\r\n    io << \"Status: \" << self.@statusCode\r\n  end\r\nend\r\n\r\nclass EntityNotFound(T) < ErrorResponse\r\n  def initialize\r\n    @statusCode = 404\r\n    @entityName = T.name\r\n  end\r\nend\r\n\r\nEntityNotFound(String).new\r\n```\r\n\r\nRunable code: https://play.crystal-lang.org/#/r/4wwc\r\n\r\n\r\nCrystal -v:\r\n\r\n> Crystal 0.26.0 (2018-08-17)\r\n>\r\n>LLVM: 6.0.1\r\n>Default target: x86_64-apple-macosx\r\n\r\nuname -a:\r\n> 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64"},"comment":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/comments/419652780","html_url":"https://github.com/crystal-lang/crystal/issues/6684#issuecomment-419652780","issue_url":"https://api.github.com/repos/crystal-lang/crystal/issues/6684","id":419652780,"node_id":"MDEyOklzc3VlQ29tbWVudDQxOTY1Mjc4MA==","user":{"login":"Meldanor","id":118621,"node_id":"MDQ6VXNlcjExODYyMQ==","avatar_url":"https://avatars2.githubusercontent.com/u/118621?v=4","gravatar_id":"","url":"https://api.github.com/users/Meldanor","html_url":"https://github.com/Meldanor","followers_url":"https://api.github.com/users/Meldanor/followers","following_url":"https://api.github.com/users/Meldanor/following{/other_user}","gists_url":"https://api.github.com/users/Meldanor/gists{/gist_id}","starred_url":"https://api.github.com/users/Meldanor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Meldanor/subscriptions","organizations_url":"https://api.github.com/users/Meldanor/orgs","repos_url":"https://api.github.com/users/Meldanor/repos","events_url":"https://api.github.com/users/Meldanor/events{/privacy}","received_events_url":"https://api.github.com/users/Meldanor/received_events","type":"User","site_admin":false},"created_at":"2018-09-08T15:49:50Z","updated_at":"2018-09-08T15:49:50Z","author_association":"NONE","body":"I don't know if accessing the name of a type is allowed or possible (I know crystal only for 2 weeks), but the compile message is at least very hard to understand and to find the error."}}
{"actor":{"display_login":"Meldanor"}}