www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9047] New: Bad error message with power ^^ operator

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

           Summary: Bad error message with power ^^ operator
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



void main() {
    import std.math;
    auto f = (double a, double b) => a ^^ b;
}



DMD 2.061alpha gives:

test.d(3): Error: undefined identifier 'std'

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 19 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9047


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|diagnostic                  |rejects-valid
                 CC|                            |andrej.mitrovich gmail.com
         AssignedTo|nobody puremagic.com        |andrej.mitrovich gmail.com
            Summary|Bad error message with      |Expression requiring
                   |power ^^ operator           |std.math fails with
                   |                            |function-local import
         OS/Version|Windows                     |All
           Severity|minor                       |normal



10:51:03 PST ---
I don't think this is a diagnostic bug, it's a problem where the compiler
rewrites the call to:

void main() {
    import std.math;
    auto f = (double a, double b) => .std.math.pow(a, b);
}

This is why you get a "undefined identifier std" message.

Using the .dot won't work here because the import is function-local.

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





 I don't think this is a diagnostic bug, it's a problem where the compiler
 rewrites the call to:
 
 void main() {
     import std.math;
     auto f = (double a, double b) => .std.math.pow(a, b);
 }
 
 This is why you get a "undefined identifier std" message.
 
 Using the .dot won't work here because the import is function-local.
The code the performs that rewriting should verify that the correctness conditions are satisfied, and otherwise possibly rewrite the ^^ with something that shows a good error message. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 07 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9047




14:59:29 PST ---
https://github.com/D-Programming-Language/dmd/pull/1438

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




15:13:35 PST ---
*** Issue 4845 has been marked as a duplicate of this issue. ***

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





 https://github.com/D-Programming-Language/dmd/pull/1438
Thank you Andrej. The usability of a language comes also from little forward steps like this :-) It's a small step, but hundreds of such steps make a difference. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 07 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9047




15:07:59 PST ---
*** Issue 8354 has been marked as a duplicate of this issue. ***

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




void main() {
    import std.stdio;
    int x = 3;
    immutable j = 2 ^^ x;
}


Error received:

temp.d(4): Error: undefined identifier 'std'


Expected error:

temp.d(4): Error: must import std.math to use ^^ operator



That problem causes curious cascades of errors like:


void main() {
    import std.stdio;
    enum size_t N = 5;
    char[N][N] mat = '0';
    int e = 0;
    foreach (immutable i, ref row; mat) {
        immutable j = (i + (2 ^^ e)) % N;
        row[j] = '1';
    }
    writeln(mat);
}



temp.d(7): Error: undefined identifier 'std'
...\dmd2\src\phobos\std\range.d(611): Error: static assert  "Cannot put a
const(dchar) into a Appender!(char[])"
...\dmd2\src\phobos\std\format.d(2163):        instantiated from here:
put!(Appender!(char[]), const(dchar))
...\dmd2\src\phobos\std\format.d(2210):        instantiated from here:
formatChar!(Appender!(char[]))
...\dmd2\src\phobos\std\format.d(2113):        instantiated from here:
formatElement!(LockingTextWriter, char[5u], char)
...\dmd2\src\phobos\std\format.d(1827):        ... (5 instantiations, -v to
show) ...
...\dmd2\src\phobos\std\stdio.d(1622):        instantiated from here:
write!(char[5u][5u],char)
temp.d(10):        instantiated from here: writeln!(char[5u][5u])

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




08:05:25 PDT ---

 temp.d(7): Error: undefined identifier 'std'
 ...\dmd2\src\phobos\std\range.d(611): Error: static assert  "Cannot put a
 const(dchar) into a Appender!(char[])"
Looks like another case of http://d.puremagic.com/issues/show_bug.cgi?id=9549 which was accidentally fixed by another pull. However your test-case still creates this cascade of errors, so maybe you should put your test-case into Issue 9549 and reopen it. My pull here fixes the first error message (to "must import std.math"), but the cascade of errors still appear. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 23 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9047






 However your test-case still creates this cascade of errors, so maybe you
 should put your test-case into Issue 9549 and reopen it.
I don't understand Issue 9549 enough, and it was opened by you, so probably I think it's better for you to copy that stuff there :-)
 My pull here fixes the first error message (to "must import std.math"), but the
 cascade of errors still appear.
OK. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 23 2013