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

Compiler bug when requiring module #8665

Closed
kalafut opened this issue Jan 9, 2020 · 9 comments · Fixed by #13760
Closed

Compiler bug when requiring module #8665

kalafut opened this issue Jan 9, 2020 · 9 comments · Fixed by #13760

Comments

@kalafut
Copy link

kalafut commented Jan 9, 2020

Hi. I hit a compiler bug that the error message said to report.

Crystal 0.32.1 (2019-12-18)

LLVM: 9.0.0
Default target: x86_64-apple-macosx

Here's the exception:

crystal run btest.cr
while requiring "bencoding.cr" (Exception)
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::TopLevelVisitor>:Nil
  from Crystal::TopLevelVisitor#visit<Crystal::Expressions>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::TopLevelVisitor>:Nil
  from Crystal::Program#top_level_semantic<Crystal::ASTNode+>:Tuple(Crystal::ASTNode+, Crystal::TypeDeclarationProcessor)
  from Crystal::Program#semantic<Crystal::ASTNode+, Bool>:Crystal::ASTNode+
  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
Caused by: Error reading file: Is a directory (Errno)
  from File@Crystal::System::FileDescriptor#unbuffered_read<Slice(UInt8)>:Int32
  from File@IO::Buffered#read<Slice(UInt8)>:Int32
  from File::read<String, Nil, Nil>:String
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::TopLevelVisitor>:Nil
  from Crystal::TopLevelVisitor#visit<Crystal::Expressions>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::TopLevelVisitor>:Nil
  from Crystal::Program#top_level_semantic<Crystal::ASTNode+>:Tuple(Crystal::ASTNode+, Crystal::TypeDeclarationProcessor)
  from Crystal::Program#semantic<Crystal::ASTNode+, Bool>:Crystal::ASTNode+
  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

Source (literally the whole file):

require "bencoding.cr"

shard.yml:

name: test
version: 0.1.0

dependencies:
  bencoding.cr:
    github:  Hamdiakoguz/bencoding.cr

Thanks!

@straight-shoota
Copy link
Member

Ooops. Amazing that nobody has not this before...

@RX14
Copy link
Contributor

RX14 commented Jan 9, 2020

That library should be called bencoding even if the github repository is called bencoding.cr

@straight-shoota
Copy link
Member

@RX14 Technically that's probably better, but nothing says library names can't end with .cr. The extension is required for files but it's not forbidden for directories.
The compiler should just checker whether the required name is actually a library file or dir and treat it accordingly.

@RX14
Copy link
Contributor

RX14 commented Jan 9, 2020

yeah, this should be fixed but worth mentinoing best practices

@straight-shoota
Copy link
Member

Right. It wasn't clear to me if your comment was just directed at the OP to give some advice or to generally rule out requiring directories ending with .cr.

@kalafut
Copy link
Author

kalafut commented Jan 9, 2020

That was my suspicion. I've been using the language for all of about one hour and it just so happened I wanted use that library for my first project. The extension did seem odd as I’d not seen it before in the tutorials.

Thanks for looking into it!

@asterite
Copy link
Member

What should be done in this case? Maybe if a directory name ends with ".cr" we should error and tell the user that directories with ".cr" are not allowed because they are confusing?

@straight-shoota
Copy link
Member

@asterite That's an option. But I'm actually not sure if this should be forbidden. The path lookup could just treat a directory as a directory even if it ends in .cr.

@Vici37
Copy link

Vici37 commented Jul 31, 2023

I just raw into this bug while trying to use https://github.com/firejox/fftw.cr 😬 Currently I'm unable to do so.

Creating a brand new crystal project where the shards.yml includes it like:

development_dependencies:
  fftw.cr:
    github: firejox/fftw.cr

And a require "fftw.cr" is made in the entry point file yields a compiler error when trying to build said entry point file:

Error reading file: Is a directory (IO::Error)
  from /crystal/src/gc/boehm.cr:132:5 in 'unbuffered_read'
  from /crystal/src/io.cr:1160:18 in 'read'
  from /crystal/src/compiler/crystal/semantic/semantic_visitor.cr:74:40 in 'visit'
  from /crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /crystal/src/enumerable.cr:463:7 in 'visit'
  from /crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /crystal/src/compiler/crystal/semantic.cr:70:7 in 'semantic:cleanup'
  from /crystal/src/compiler/crystal/compiler.cr:171:14 in 'compile:combine_rpath'
  from /crystal/src/compiler/crystal/command.cr:341:5 in 'run'
  from /crystal/src/compiler/crystal.cr:11:1 in '__crystal_main'
  from /crystal/src/crystal/main.cr:129:5 in 'main'
  from src/env/__libc_start_main.c:95:2 in 'libc_start_main_stage2'
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

This lib has existed for awhile, but has no "Issues", so I'm not sure if it's actually been used before :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants