[Issue 8354] Some missing "import std.math to use ^^ operator" error messages

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jul 14 14:11:24 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8354


Masahiro Nakagawa <repeatedly at gmail.com> changed:

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


--- Comment #1 from Masahiro Nakagawa <repeatedly at 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: -------


More information about the Digitalmars-d-bugs mailing list