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

Conditional compilation issue #7108

Closed
azrafe7 opened this issue May 29, 2018 · 8 comments
Closed

Conditional compilation issue #7108

azrafe7 opened this issue May 29, 2018 · 8 comments

Comments

@azrafe7
Copy link
Contributor

azrafe7 commented May 29, 2018

Have not been able to make a general and succint example out of this, but it was reproducing in my code base and this snippet (http://try-haxe.mrcdk.com/#e66Ed) seems to somehow reproduce the issue (although not faithfully):

class Test {
  static function main() {
    trace("Haxe is great!");
    #if js
      trace('x');
    #elif js
      trace('elif');
    #else
      trace('end');
    #end
  }
}

Maybe "elif" was allowed some time ago and has not been supported in latest versions?

@azrafe7
Copy link
Contributor Author

azrafe7 commented May 29, 2018

haxe 4.0.0 preview

As always sorry if I'm misunderstanding something.

@azrafe7
Copy link
Contributor Author

azrafe7 commented May 29, 2018

PS: from google searches it seems that #elif was never supported, but somehow gets through the parser anyhow.

(EDIT: well the code is somewhat succint, but I don't know if it applies to all targets)

@Simn
Copy link
Member

Simn commented May 30, 2018

It's a valid token as far as the lexer is concerned. All tokens are skipped in inactive branches, so this never comes up as a problem.

Maybe we should indeed error on invalid #-tokens in these cases.

@Simn Simn added this to the Release 4.0 milestone May 30, 2018
@EricBishton
Copy link
Member

You mean: "It's a valid token as any space-delimited set of characters is a [skipped] token in inactive compilation branches," right? It would be nice if inactive CC branches did spit out syntax errors, but then you couldn't #if 0 ... { invalid, half written, code } #endif' any more just to get a test compile. Well.. actually, you could detect '0' as a special circumstance...

@azrafe7 '#elseif' is the token that denotes a second branch for conditional compilation.

@Simn - If you're going to think about creating an error when you see '#unrecognized' in a source file,
I'd love to see #error "message" be a recognized sequence so that you could do something like:

hxcpp_debugger.hx

  #if !hxcpp
  #error "hxcpp debugging can only be used in C++ targets."
  #endif

And that would stop the compiler with an error message:

  hxcpp_debugger.hx: 2: lines 2-2: hxcpp debugging can only be used in C++ targets.

(or whatever the 4.0 error message format will be.)

@Simn
Copy link
Member

Simn commented May 30, 2018

You mean: "It's a valid token as any space-delimited set of characters is a [skipped] token in inactive compilation branches," right?

That's not true, we still lex normally in inactive branches. The lexer dies on #if false £ #end or any other unrecognized character.

I'd love to see #error "message" be a recognized sequence

#error "message" has been around for a long time.

@EricBishton
Copy link
Member

EricBishton commented May 30, 2018

#error "message" has been around for a long time.

My bad. Not sure why I thought it wasn't.

@Simn
Copy link
Member

Simn commented May 30, 2018

Probably because it's not properly documented.

@azrafe7
Copy link
Contributor Author

azrafe7 commented May 31, 2018

Thanks @EricBishton (figure that out just after posting).

@Simn, yes, why not error out in this cases? (I see you only added the documentation label)

@Simn Simn modified the milestones: Release 4.0, Backlog Sep 5, 2018
@Simn Simn closed this as completed in dd9f1f6 Jul 2, 2019
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

3 participants