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

Using with ... yield twice #5225

Open
jbomanson opened this issue Nov 1, 2017 · 7 comments
Open

Using with ... yield twice #5225

jbomanson opened this issue Nov 1, 2017 · 7 comments

Comments

@jbomanson
Copy link

The following prints almost two pages of weird characters on my screen. Also, the output changes from run to run. The code is insane, I no longer remember what I was trying to accomplish with it and it should not actually compile.

def insane_method(value)
  with value yield
  with self yield
end

puts insane_method(:abc) { itself }

I am using Crystal 0.23.1 [e2a1389] (2017-07-13) LLVM 3.8.1 on ubuntu 16.04 LTS.

My guess is that the problem here has to do with how only one of the two receivers responds to itself, but somehow the compiler does not catch that.

Moreover, trying to build with --release results in a failure during the codegen phase with the following error:

crystal: /var/cache/omnibus/src/llvm/llvm-3.8.1.src/lib/CodeGen/LexicalScopes.cpp:160: llvm::LexicalScope* llvm::LexicalScopes::getOrCreateRegularScope(const llvm::DILocalScope*): Assertion `cast<DISubprogram>(Scope)->describes(MF->getFunction())' failed.
/usr/bin/crystal: line 102: 433222 Aborted                 "$INSTALL_DIR/embedded/bin/crystal" "$@"
@lbguilherme
Copy link
Contributor

This is a bug in LLVM 3.8. Updating to LLVM 3.9 fixes this.

See #4719

@asterite
Copy link
Member

asterite commented Nov 1, 2017

No, it's a bug in the compiler

  1. There's no self there
  2. Even if it's in a class it breaks. with ... yield can't receive two different types (or maybe yes, but it should be the union, I don't know)

@jbomanson
Copy link
Author

I now tried with the crystal version at https://github.com/crystal-lang/crystal/releases/download/0.24.0/crystal-0.24.0-2-linux-x86_64.tar.gz, which reports itself as

Crystal 0.23.0+313 [ea4187c57] (2017-10-27)

LLVM: 3.9.1
Default target: x86_64-unknown-linux-gnu

This time I get the following error when running it:

Invalid memory access (signal 11) at address 0x4
[0x44b335] *CallStack::print_backtrace:Int32 +117
[0x4402f6] __crystal_sigfault_handler +70
[0x7f5869e1b390] ???
[0x44d075] *String#to_slice:Slice(UInt8) +21
[0x44dce8] *String#to_s<IO::FileDescriptor>:Nil +24
[0x45b6a1] *IO::FileDescriptor +17
[0x485ddd] *Symbol#to_s<IO::FileDescriptor>:IO::FileDescriptor +45
[0x45c7b5] *IO::FileDescriptor +21
[0x45c77e] *IO::FileDescriptor +14
[0x440335] *puts<Symbol>:Nil +37
[0x4337ee] __crystal_main +1598
[0x4404b6] *_crystal_main<Int32, Pointer(Pointer(UInt8))>:Nil +6
[0x486306] *Crystal::main_user_code<Int32, Pointer(Pointer(UInt8))>:Nil +6
[0x4861d2] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +50
[0x43e6f6] main +6
[0x7f586943e830] __libc_start_main +240
[0x4330d9] _start +41
[0x0] ???

Compilation with --release still fails with:

crystal: /var/cache/omnibus/src/llvm/llvm-3.9.1.src/lib/CodeGen/LexicalScopes.cpp:159: llvm::LexicalScope* llvm::LexicalScopes::getOrCreateRegularScope(const llvm::DILocalScope*): Assertion `cast<DISubprogram>(Scope)->describes(MF->getFun
ction())' failed.
/m/home/home8/82/jbomanso/data/Downloads/crystal-0.24.0-2/bin/crystal: line 102: 437332 Aborted                 "$INSTALL_DIR/embedded/bin/crystal" "$@"

@makenowjust
Copy link
Contributor

I agree with "with ... yield can't receive two different types" and I implement such a feature at this branch as an experiment.

makenowjust added a commit to makenowjust/crystal that referenced this issue Nov 1, 2017
makenowjust added a commit to makenowjust/crystal that referenced this issue Nov 1, 2017
RX14 pushed a commit that referenced this issue Nov 2, 2017
@asterite
Copy link
Member

asterite commented Nov 3, 2017

Also happens with this:

def foo
  with 1 yield
  with 1.5 yield
end

foo do
  p abs
end

So it has nothing to do with self.

That's a bit more difficult to fix.

@jhass
Copy link
Member

jhass commented Jun 6, 2019

These days we get a validation error for this:

Module validation failed: Call parameter type does not match function signature!

@vlazar
Copy link
Contributor

vlazar commented Oct 13, 2019

Checked in

$ crystal --version
Crystal 0.31.1 (2019-10-02)

LLVM: 8.0.1
Default target: x86_64-apple-macosx

Original example seem to be fixed now

$ crystal test.cr
Showing last frame. Use --error-trace for full trace.

In test.cr:3:8

 3 | with self yield
          ^---
Error: there's no self in this scope

Ary's example still fails with

Module validation failed: Call parameter type does not match function signature!

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

No branches or pull requests

6 participants