Thread overview
[Issue 16666] type inside 'static if' can't be used before import
[Issue 16666] core.sys.posix.sys.types uses c_long without importing its definition
Nov 13, 2016
Nemanja Boric
Mar 27, 2022
duser@neet.fi
Jun 02, 2022
kinke
Jun 02, 2022
kinke
Jun 03, 2022
Iain Buclaw
Dec 17, 2022
Iain Buclaw
November 13, 2016
https://issues.dlang.org/show_bug.cgi?id=16666

Nemanja Boric <4burgos@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |4burgos@gmail.com

--- Comment #1 from Nemanja Boric <4burgos@gmail.com> ---
Very strange, because to me it looks like it actually imports - it imports `core.sys.posix.config` which in turns publicly imports `core.stdc.config`, but it doesn't work unless I put

```
import core.sys.posix.config: c_long;
```

inside core.sys.posix.sys.types.

--
March 27, 2022
https://issues.dlang.org/show_bug.cgi?id=16666

duser@neet.fi changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |duser@neet.fi
          Component|druntime                    |dmd
           Hardware|x86_64                      |All
            Summary|core.sys.posix.sys.types    |type inside 'static if'
                   |uses c_long without         |can't be used before import
                   |importing its definition    |
                 OS|Linux                       |All
           Severity|enhancement                 |normal

--- Comment #2 from duser@neet.fi ---
underlying issue seems to be this:

// main.d
my_long x;
import core_stdc_config;

// core_stdc_config.d
static if (1)
        alias my_long = long;
else
        alias my_long = long;

main.d(1): Error: undefined identifier `my_long`

error goes away if "my_long x;" is moved after the import, ": my_long" is added to make it a selective import, or if the "static if" is removed

--
June 02, 2022
https://issues.dlang.org/show_bug.cgi?id=16666

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |industry
                 CC|                            |kinke@gmx.net
           Severity|normal                      |critical

--- Comment #3 from kinke <kinke@gmx.net> ---
Raising importance to critical, as we seem to have hit the same problem with v2.100, dustmited to a trivial

```
// crypto.d:
import types;
int EVP_PKEY_derive_init_ex(EVP_KEYEXCH*);

// types.d:
import crypto;
version (WORKING)
    struct EVP_KEYEXCH;
else static if (true)
    struct EVP_KEYEXCH;
```

`dmd -o- types.d` fails with an 'undefined identifier EVP_KEYEXCH' error; `-version=WORKING` makes it work, showing the difference of static-if vs. version condition. Compiling the other module (`dmd -o- crypto.d`) works fine.

--
June 02, 2022
https://issues.dlang.org/show_bug.cgi?id=16666

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=20905

--
June 03, 2022
https://issues.dlang.org/show_bug.cgi?id=16666

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw@gdcproject.org

--- Comment #4 from Iain Buclaw <ibuclaw@gdcproject.org> ---
(In reply to kinke from comment #3)
> Raising importance to critical, as we seem to have hit the same problem with v2.100, dustmited to a trivial
> 
> ```
> // crypto.d:
> import types;
> 
> 
> // types.d:
> import crypto;
> version (WORKING)
>     struct EVP_KEYEXCH;
> else static if (true)
>     struct EVP_KEYEXCH;
> ```
> 
> `dmd -o- types.d` fails with an 'undefined identifier EVP_KEYEXCH' error; `-version=WORKING` makes it work, showing the difference of static-if vs. version condition. Compiling the other module (`dmd -o- crypto.d`) works fine.

Just highlights the linear expansion of imports and static if's in a compilation.


module crypto
  -> import object
  -> import types
    -> module types
      -> import object
      -> import crypto
        -> module crypto
      -> static if (true)
        -> struct EVP_KEYEXCH
  -> int EVP_PKEY_derive_init_ex(EVP_KEYEXCH*)

vs.

module types;
  -> import object
  -> import crypto
    -> module crypto
      -> import object
      -> import types
        -> module types
      -> int EVP_PKEY_derive_init_ex(EVP_KEYEXCH*)


I can't see myself being happy with anything other than a total rethink of how the first semantic pass walks over all nodes.

The "quick fix" would be to extend this related PR fix to look in more places.

https://github.com/dlang/dmd/pull/9873

But that would open up a Pandora's box more problems.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=16666

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P2

--
December 13
https://issues.dlang.org/show_bug.cgi?id=16666

--- Comment #5 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19204

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--