Thread overview
Selective import seems to be importing more than just specified symbol
January 08
-----------------------------------------------------------
module redblacktree;

import std.container : RedBlackTree;
import honeycomb : Location;   // Seems to import all of honeycomb.d symbols

struct Node
{
    this(Location locaction, uint f)
    {
        this.location = location;
        this.f = f;
    }
    Location location;
    uint f;
}


unittest
{
    auto priorQ = new RedBlackTree!(Node, "a.f < b.f", true);
    Node n1 = Node( Location(1,2), 33);
    // etc.
}
-----------------------------------------------------------

I'm trying to retrofit unit testing in an existing D project. But when I run the
command:

rdmd -main -unittest redblacktree.d

This error is returned:

honeycomb.d(11): Error: unable to read module `sdl`
honeycomb.d(11):        Expected 'bindbc\sdl.d' or 'bindbc\sdl\package.d' in one of the following import paths:
import path[0] = .
import path[1] = C:\D\dmd2\windows\bin64\..\..\src\phobos
import path[2] = C:\D\dmd2\windows\bin64\..\..\src\druntime\import

honeycomb.d module is just:

-----------------------------------------------------------
module honeycomb;

import bindbc.sdl;

struct Location   // holds a hex of a hexboard
{
    int r;  // row
    int c;  // colum
}
-----------------------------------------------------------

I thought that the line
import honeycomb : Location;
would only import the symbol struct Location?

January 08

On Wednesday, 8 January 2025 at 02:07:46 UTC, WhatMeWorry wrote:

>

rdmd -main -unittest redblacktree.d

This error is returned:

honeycomb.d(11): Error: unable to read module sdl
honeycomb.d(11): Expected 'bindbc\sdl.d' or 'bindbc\sdl\package.d' in one of the following import paths:
import path[0] = .
import path[1] = C:\D\dmd2\windows\bin64....\src\phobos
import path[2] = C:\D\dmd2\windows\bin64....\src\druntime\import

honeycomb.d module is just:


module honeycomb;

import bindbc.sdl;

struct Location // holds a hex of a hexboard
{
int r; // row
int c; // colum
}

I thought that the line
import honeycomb : Location;
would only import the symbol struct Location?

Selective imports affect which symbols in an imported module are accessible. They have no effect on imports in other modules.

In your redblacktree module, you are telling the compiler that you only care about Location and don't want any other symbols in honeycomb to be accessible. If you had any other symbols in honeycomb, like another struct type or a function, you wouldn't be able to access them in redblacktree.

However, the compiler still needs to parse the imports that honeycomb brings in so that it knows what symbols are accessible in the honeycomb module itself. The selective import has no impact on that. Just imagine what would happen if you actually called any SDL functions from inside Location, say in a constructor or something. How would that work if your selective import caused the compiler to ignore the import bindbc.sdl?

You need bindbc.sdl on your import path for this to work.

January 09

On Wednesday, 8 January 2025 at 02:07:46 UTC, WhatMeWorry wrote:

>

I thought that the line
import honeycomb : Location;
would only import the symbol struct Location?

So imagine a honeycomb.d file that looks like this:

module honeycomb;

import std.stdio;

struct Location {
    int r;
    int c;
    File foo;
}

A nonsense file, but I hope you can see that the compiler has to still process the file and analyze it even if you don't use all of it.

-Steve