www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10803] New: pragma(msg, ...) fails with enum TypeTuple: compilaton error

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10803

           Summary: pragma(msg, ...) fails with enum TypeTuple: compilaton
                    error
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: 2krnk gmx.net



see example below. with the last pragma commented out, the program works fine,
including 'enum er'.
with the pragma active, compilation fails. error message appears
at point of pragma processing, with the line number of the
enum er definition though.
...Error: variable _er_field_0,1,2 cannot be read at compile time

tested with DMD 2.063.2 win32 on home machine as well as with 2.063.2 64b and
latest git head via DPaste http://dpaste.dzfl.pl/36674a13


module testcase;

import std.stdio, std.typetuple;

enum ok = [TypeTuple!("one", "two", "three")];
enum er = TypeTuple!("one", "two", "three");

pragma( msg, "one", "two", "three" );
    // onetwothree
pragma( msg, ok );
    // ["one", "two", "three"]
pragma( msg, TypeTuple!("one", "two", "three") );
    // tuple("one", "two", "three")
pragma( msg, er );
    // with the pragma above commented out, the program works fine,
    // including the enum er.
    // with the pragma active, compilation fails. error message appears
    // at point of pragma processing, with the line number of the
    // enum er definition though:
    // Error: variable _er_field_0,1,2 cannot be read at compile time

void main(){
    writeln( "one", "two", "three" );
        // onetwothree
    writeln( ok );
        // ["one", "two", "three"]
    writeln( er );
        // onetwothree
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 11 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10803


Dicebot <public dicebot.lv> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |public dicebot.lv



Ugh, I expected this line:

 enum er = TypeTuple!("one", "two", "three");
to either not compile at all or be equivalent to enum er = ("one", "two", three"); Type tuple on its own is not a value that can be assigned to something, only aliasing or expanding it should be legal. My guess is that dirty `enum` implementation details get observed here. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10803


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE




 enum er = TypeTuple!("one", "two", "three");
to either not compile at all or be equivalent to enum er = ("one", "two", three");
It should work. And, the root cause of the issue is just same as bug 9017. *** This issue has been marked as a duplicate of issue 9017 *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10803





 It should work. And, the root cause of the issue is just same as bug 9017.
Proof-link to the docs? And what is exact meaning of it (what is type of of enum)? If this is legal, why this: auto foo() { return TypeTuple!("aaa", "bbb"); } is not? We are skating on a thin ice here. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10803





 Proof-link to the docs? And what is exact meaning of it (what is type of of
 enum)?
D has "tuple of variables", and today it is accepted in statement scope and aggregate fields. import std.typetuple; void test1() { auto tup1 = TypeTuple!(1, "a"); pragma(msg, typeof(tup1)); // (int, string) assert(tup1[0] == 1); assert(tup1[1] == "a"); tup1[0] = 2; tup1[1] = "b"; assert(tup1[0] == 2); assert(tup1[1] == "b"); enum tup2 = TypeTuple!(1, "a"); pragma(msg, typeof(tup2)); // (int, string) assert(tup2[0] == 1); assert(tup2[1] == "a"); } struct Tuple(TL...) { TL tup3; } alias ConcreteTuple = Tuple!(int, string); // BUG: should be accepted as same as tup1 to 3 //auto tup4 = TypeTuple!(1, "a"); //enum tup5 = TypeTuple!(1, "a"); I think that should also be accepted in module scope. If this is legal, why this:
 
 auto foo()
 {
     return TypeTuple!("aaa", "bbb");
 } 
 
 is not?
That's completely irrelevant thing. D's built-in tuple is not packed, and D ABI does not support "multiple value return from function". -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10803




If you are sure this is intended behavior it needs to be very clearly
documented at http://dlang.org/tuple.html. At the very least. Because right now
I can find no mention in docs that type tuples that consist purely from
expressions have that special meaning. 

It is a quite confusing behavior considering what pure type tuple and
std.typecons.Tuple are.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10803





 If you are sure this is intended behavior it needs to be very clearly
 documented at http://dlang.org/tuple.html. At the very least. Because right now
 I can find no mention in docs that type tuples that consist purely from
 expressions have that special meaning. 
It's documented in "Tuple Declarations" part.
 It is a quite confusing behavior considering what pure type tuple and
 std.typecons.Tuple are.
The confusion comes from the naming. I prefer to use different name "sequence" for the built-in tuple, but it is not consensus... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10803





 It's documented in "Tuple Declarations" part.
"Tuple Declarations" part speaks about something quite different - that you can use type tuple to group/ungroup parameter lists and reference that parameters using positional syntax, not via names. Now, after you comment, I see how actual tuple semantics/implementation makes both cases related. But documentation does not speak about what `TL` and `tl` actually are in that example or what happens from the type system point of view. It is just a single use case and it looks as special syntax sugar with no extra meaning. I am asking for a more detailed explanation in that part.
 The confusion comes from the naming. I prefer to use different name "sequence"
 for the built-in tuple, but it is not consensus...
No, that is something I got used to. I am speaking about something different: enum a = TypeTuple!(int, string); // does not compile enum a = TypeTyple!("aaa", "bbb"); // works, typeof(a) == TypeTuple!(string, string), has no defined ABI enum a = tuple("aaa", "bbb"); // works, typeof(a) == Tuple!(string, string), is technically a struct 3 cases very similar syntax-wise and so different in practice. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10803






 It's documented in "Tuple Declarations" part.
"Tuple Declarations" part speaks about something quite different - that you can use type tuple to group/ungroup parameter lists and reference that parameters using positional syntax, not via names. Now, after you comment, I see how actual tuple semantics/implementation makes both cases related. But documentation does not speak about what `TL` and `tl` actually are in that example or what happens from the type system point of view. It is just a single use case and it looks as special syntax sugar with no extra meaning. I am asking for a more detailed explanation in that part.
Ah, OK. I was wrong. D language has following feature: - If given initializer is an Expression Tuple, type inference would make the declaration Tuple Declaration. alias EL = TypreTuple!(1, "str"); // Expression Tuple alias TL = TypeTuple!(int, string); // Type Tuple auto tup = EL; is mostly same as: TL tup; tup[0] = TL[0]; tup[1] = TL[1]; Certainly this is not precisely documented in dlang.org/tuple.html -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2013