www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8354] New: Some missing "import std.math to use ^^ operator" error messages

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

           Summary: Some missing "import std.math to use ^^ operator"
                    error messages
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            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-07-06 17:44:32 PDT ---
A wrong D2 program:

void main() {
    int x1 = 10;
    auto y1 = x1 ^^ 5;
}


It gives a correct error message:
test.d(3): Error: must import std.math to use ^^ operator

------------------------

But adding a second power it gives a wrong error message (dmd 2.060alpha):

void main() {
    int x1 = 10;
    auto y1 = x1 ^^ 5;
    double x2 = 10.5;
    auto y2 = x2 ^^ 5;
}


test.d(3): Error: must import std.math to use ^^ operator
test.d(5): Error: undefined identifier 'std'


Here I'd like the second power to give an error message similar to the first
one.

------------------------

Something similar happens if you import pow, this time for both powers:


import std.math: pow;
void main() {
    int x1 = 10;
    auto y1 = x1 ^^ 5;
    double x2 = 10.5;
    auto y2 = x2 ^^ 5;
}


test.d(4): Error: undefined identifier 'std'
test.d(6): Error: undefined identifier 'std'

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


Masahiro Nakagawa <repeatedly gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |repeatedly gmail.com


--- Comment #1 from Masahiro Nakagawa <repeatedly gmail.com> 2012-07-14
14:11:22 PDT ---
(In reply to comment #0)
 A wrong D2 program:
 
 void main() {
     int x1 = 10;
     auto y1 = x1 ^^ 5;
 }
 
 
 It gives a correct error message:
 test.d(3): Error: must import std.math to use ^^ operator
 
 ------------------------
 
 But adding a second power it gives a wrong error message (dmd 2.060alpha):
 
 void main() {
     int x1 = 10;
     auto y1 = x1 ^^ 5;
     double x2 = 10.5;
     auto y2 = x2 ^^ 5;
 }
 
 
 test.d(3): Error: must import std.math to use ^^ operator
 test.d(5): Error: undefined identifier 'std'
 
 
 Here I'd like the second power to give an error message similar to the first
 one.

Following patch fixes this problem: ----- diff --git a/src/expression.c b/src/expression.c index 392ca06..9916fbe 100644 --- a/src/expression.c +++ b/src/expression.c -11472,6 +11472,7 Expression *PowExp::semantic(Scope *sc) } static int importMathChecked = 0; + static bool importMath = false; if (!importMathChecked) { importMathChecked = 1; -11480,13 +11481,20 Expression *PowExp::semantic(Scope *sc) //printf("\t[%d] %s\n", i, mi->toChars()); if (mi->ident == Id::math && mi->parent->ident == Id::std && - !mi->parent->parent) + !mi->parent->parent) { + importMath = true; goto L1; + } } error("must import std.math to use ^^ operator"); return new ErrorExp(); L1: ; + } else { + if (!importMath) { + error("must import std.math to use ^^ operator"); + return new ErrorExp(); + } } e = new IdentifierExp(loc, Id::empty); -----
 ------------------------
 
 Something similar happens if you import pow, this time for both powers:
 
 
 import std.math: pow;
 void main() {
     int x1 = 10;
     auto y1 = x1 ^^ 5;
     double x2 = 10.5;
     auto y2 = x2 ^^ 5;
 }
 
 
 test.d(4): Error: undefined identifier 'std'
 test.d(6): Error: undefined identifier 'std'

I can't judge the this problem is bug or spec. 'import std.math: pow' does not import 'std' namespace, but dmd replaces ^^ with std.math.sqrt or std.math.pow. This is the same problem below: ----- import std.math : sqrt; void main() { real x1 = 10; auto y1 = std.math.sqrt(x1); } m.d(6): Error: undefined identifier std ----- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 14 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8354



--- Comment #2 from github-bugzilla puremagic.com 2012-08-06 06:33:44 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/46610791735d157bd7558ddf34fbd0d875367452
Fix issue 8354 - Some missing "import std.math to use ^^ operator" error
messages

This patch fixes a wrong error message of multiple power expressions without
'import std.math'.
This patch does not fix 'import std.math: pow;' issue, because
'^^' spec is a another problem.

https://github.com/D-Programming-Language/dmd/commit/cef1bbfdcd9282934ff6f1b07617254753334799
Merge pull request #1048 from repeatedly/issue8354

Fix issue 8354 - Some missing "import std.math to use ^^ operator" error...

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


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

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


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



--- Comment #3 from github-bugzilla puremagic.com 2012-08-19 01:03:06 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/21f32ed72f75f0eaf68f06da62eb4c8e3e0a2c98
fix Issue 8354 - Some missing "import std.math to use ^^ operator" error
messages

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


Puneet Goel <puneet coverify.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |puneet coverify.org
         Resolution|FIXED                       |


--- Comment #4 from Puneet Goel <puneet coverify.org> 2013-01-10 01:00:20 PST
---
If std.math is imported in one module and power (^^) expression is used in
another module and both the modules are compiled together, we again see the
same confusing error:

bar.d(1): Error: undefined identifier 'std'


Here is the testcase (compile with -- dmd foo.d bar.d):

// File foo.d
import std.math;
void foo() { }

// File bar.d
void bar(int i) { 2^^i; }

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |DUPLICATE


--- Comment #5 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-01-10
15:07:59 PST ---
(In reply to comment #4)
 If std.math is imported in one module and power (^^) expression is used in
 another module and both the modules are compiled together, we again see the
 same confusing error:
 
 bar.d(1): Error: undefined identifier 'std'
 
 
 Here is the testcase (compile with -- dmd foo.d bar.d):
 
 // File foo.d
 import std.math;
 void foo() { }
 
 // File bar.d
 void bar(int i) { 2^^i; }

This will be fixed with pull for Issue 9047. *** This issue has been marked as a duplicate of issue 9047 *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 10 2013