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

__FILE__ undefined #44

Open
mitch000001 opened this issue Jun 2, 2017 · 1 comment
Open

__FILE__ undefined #44

mitch000001 opened this issue Jun 2, 2017 · 1 comment

Comments

@mitch000001
Copy link
Member

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8.3 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN="/Users/401208/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/401208"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/9q/wtg2gqwd57x88fy6qw79klsn6zl9w9/T/go-build854393630=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What version of GoRuby are you using (git show -s --format=%H or goruby -version)?

git show -s --format=%H
# => 07b0c0a9b40cc6551c20cc830965e315ab61c803

What did you do?

cat <<EOF > /tmp/foo
> puts __FILE__
> EOF
go run main.go /tmp/foo

What did you expect to see?

/tmp/foo

What did you see instead?

undefined local variable or method `__FILE__' for main:Object
exit status 1
@mitch000001 mitch000001 added this to the Add rubyspec support milestone Jun 2, 2017
@skx
Copy link
Contributor

skx commented Jan 19, 2019

This is an interesting bug, with the current repository:

  $ git show -s --format=%H
  ee5b7274d84c124a2bd3b3d6f1e2c78d31148cc5

There have obviously been changes now, such that __FILE__ is defined. The following code works:

   frodo ~/go/src/github.com/goruby/goruby $ cat > t.rb <<EOF
   > puts( __FILE__ )
   > EOF
   frodo ~/go/src/github.com/goruby/goruby $ ./goruby t.rb 
   t.rb

However this code fails:

     puts __FILE__

(Outputs an empty line.)

I've updated kernel.go:

   func kernelPuts(context CallContext, args ...RubyObject) (RubyObject, error) {
   	out := ""
   	fmt.Printf("Argument count %d\n", len(args))
   	for i, arg := range args {
   		fmt.Printf("Arg %i: %v\n", i, arg)
   		out += arg.Inspect()
   	}
   
   	fmt.Println(out)
   	return NIL, nil
   }

Now the sample program that works outputs things you'd expect:

  $ cat  tt.rb
  puts( __FILE__ )
  $ go build . && ./goruby tt.rb 
  Argument count 1
  Arg %!i(int=0): &{tt.rb}
  tt.rb

But the version without the parenthesis receives nothing:

 $ cat t.rb
 puts __FILE__
 $ go build . && ./goruby t.rb 
 Argument count 0

So something odd is going on there :)

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

No branches or pull requests

2 participants