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

__traits(compiles, ...) fails to see valid enum symbols #18812

Open
dlangBugzillaToGithub opened this issue Apr 6, 2014 · 2 comments
Open

__traits(compiles, ...) fails to see valid enum symbols #18812

dlangBugzillaToGithub opened this issue Apr 6, 2014 · 2 comments
Labels

Comments

@dlangBugzillaToGithub
Copy link

det reported this on 2014-04-06T16:23:40Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=12532

CC List

Description

under certain circumstances, eg when called from a template using mixin and static if, __traits(compiles, ...)  fails to see valid enum symbols. (if 'enum' in following example is replaced by 'const bool' or 'immutable bool' all symbols are found.)

=== EXAMPLE ===

template valid(string mem){
    pragma(msg, "instantiation of 'valid' with: "~mem);
    static if( !__traits( compiles, mixin(mem) ) ){
        enum valid = false;
    }else{
        enum valid =  true;
     }
}

enum ok = valid!"works";
pragma(msg, "found 'works'? "~ok.stringof );
// true - fine, recognizes 'works' later in module scope

enum foo = valid!"bar";
pragma(msg, "found 'bar'? "~foo.stringof );
// true - fine, recognizes 'bar' laterin module scope

enum bar = valid!"foo";
pragma(msg, "found 'foo'? "~bar.stringof );
// false - fails to see 'foo' earlier in module scope!

enum works = true;

void main(){}
@dlangBugzillaToGithub
Copy link
Author

monarchdodra commented on 2014-04-06T23:09:32Z

Reduced:

//----
enum a = is(typeof(b));
enum b = is(typeof(a));

pragma(msg, a); //true
pragma(msg, b); //false
//----

I'm not sure this is actually resolvable...?

@dlangBugzillaToGithub
Copy link
Author

2krnk commented on 2014-04-07T07:20:53Z

(In reply to comment #1)
> Reduced:
> 
> //----
> enum a = is(typeof(b));
> enum b = is(typeof(a));
> 
> pragma(msg, a); //true
> pragma(msg, b); //false
> //----
> 
> I'm not sure this is actually resolvable...?

sorry, i should have reduced it to

enum a = __traits(compiles, b);
pragma(msg, a);                 // true
enum b = __traits(compiles, a);
pragma(msg, b);                 // false

guess i was too preoccupied with issue 12533. however, i think b should be true, __traits(compiles, ...) should not need the value or type of a. in other words, it should be able to see that a symbol is defined without caring what it actually is. as a matter of fact, in

enum c;
pragma(msg, typeof(c));         // _error_
pragma(msg, is(typeof(c)) );    // false
enum d = __traits(compiles, c);
pragma(msg, d);                 // true

this is kinda happening.

@thewilsonator thewilsonator added the Feature:traits Relating to __traits label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants