Giter Site home page Giter Site logo

Comments (9)

kddnewton avatar kddnewton commented on July 29, 2024

This is by design. When you pass scopes, we assume you are parsing an eval. When parsing an eval, a syntax error is not raised for those jumps. Instead, it relies on the compiler to evaluate whether or not they are valid. This matches CRuby semantics.

from prism.

andrykonchin avatar andrykonchin commented on July 29, 2024

Hm, but SyntaxError is raised in CRuby:

$ ruby -v test.rb
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin23]
(eval at test.rb:1): (eval at test.rb:1):1: Invalid break (SyntaxError)

test.rb:

eval("def m; break; end")

Ah, you mean it's a responsibility of compiler. Got it 👍

from prism.

kddnewton avatar kddnewton commented on July 29, 2024

Yeah, unfortunately. Consider for instance the difference between 0 rescue next and eval("0 rescue next"). The second raises Can't escape from eval with next.

from prism.

eregon avatar eregon commented on July 29, 2024

Is it mostly about different error messages? I'm not sure if that difference is important enough to have this behavior differ with scopes.
For the def m; break; end case it seems to behave the same within or outside eval in CRuby, so it feels like Prism could always give a syntax error for that one, no?
It's not very important, but it would avoid duplicating this logic in the compiler/translator, where it feels wrong/annoying to do so.

from prism.

eregon avatar eregon commented on July 29, 2024

Some other examples:
def m; retry; end Prism seems to always error for this, eval or not, good.
module M; yield; end Prism seems to only handle (= error) it if not in eval. This feels very much like a syntactic restriction, so would be nicer if Prism handled it always.

from prism.

kddnewton avatar kddnewton commented on July 29, 2024

I'll try to find which tests were failing, but when I implemented this I got a couple more test-all tests passing. There are some things that are relying on this behavior.

from prism.

kddnewton avatar kddnewton commented on July 29, 2024

Ahh, it was the ERB tests. We need this to not error out in case you're parsing an ERB file

from prism.

eregon avatar eregon commented on July 29, 2024

We need this to not error out in case you're parsing an ERB file

I'm not following, could you give a concrete example?
Which specific jump should not error when parsing an ERB file?
And how comes there is no error from compile.c then, i.e. how come one can distinguish between parser and compile.c in that case? (eval does both).

from prism.

eregon avatar eregon commented on July 29, 2024

Ah maybe it's related to Ripper? I've seen https://bugs.ruby-lang.org/issues/20460 now

from prism.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.