Thread overview
[Issue 9047] New: Bad error message with power ^^ operator
[Issue 9047] Expression requiring std.math fails with function-local import
Jan 07, 2013
Andrej Mitrovic
Jan 07, 2013
Andrej Mitrovic
Jan 07, 2013
Andrej Mitrovic
Jan 10, 2013
Andrej Mitrovic
Mar 23, 2013
Andrej Mitrovic
November 19, 2012
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


--- Comment #0 from bearophile_hugs@eml.cc 2012-11-19 14:43:53 PST ---
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: -------
January 07, 2013
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


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-07 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: -------
January 07, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9047



--- Comment #2 from bearophile_hugs@eml.cc 2013-01-07 11:14:42 PST ---
(In reply to comment #1)
> 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: -------
January 07, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9047



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-07 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: -------
January 07, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9047



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-07 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: -------
January 07, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9047



--- Comment #5 from bearophile_hugs@eml.cc 2013-01-07 15:15:29 PST ---
(In reply to comment #3)
> 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: -------
January 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9047



--- Comment #6 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-10 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: -------
March 23, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9047



--- Comment #7 from bearophile_hugs@eml.cc 2013-03-23 07:54:19 PDT ---
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: -------
March 23, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9047



--- Comment #8 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-23 08:05:25 PDT ---
(In reply to comment #7)
> 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: -------
March 23, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9047



--- Comment #9 from bearophile_hugs@eml.cc 2013-03-23 12:41:29 PDT ---
(In reply to comment #8)

> 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: -------