private selective import + overload = breaks accessibility rules

rumbu rumbu at rumbu.ro
Tue Jan 16 18:13:27 UTC 2018


module a;

private import std.math: isNaN;

//custom overload
public bool isNaN(int i) { return false; }


=============================

module b;
import a;

void foo()
{
     bool b = isNaN(float.nan);
     //compiles successfully calling std.math.isNaN even it should 
not be visible.
}

Is this normal behavior or a bug?

OK, let's try another:

module b;
import a;
import std.math; // <== note this

void foo()
{
     bool b = isNaN(float.nan);
}

It ends in a very funny error message:

Error: std.math.isNaN!float.isNaN at src\phobos\std\math.d(5335) 
conflicts with std.math.isNaN!float.isNaN at 
src\phobos\std\math.d(5335)

Real life context:

the private import: 
https://github.com/rumbu13/decimal/blob/master/src/decimal/decimal.d#L320

the overload:
https://github.com/rumbu13/decimal/blob/master/src/decimal/decimal.d#L4201

If the end user wants to use my module like this:

import std.math;
import decimal;

he'll get the nice error message above.
	




More information about the Digitalmars-d-learn mailing list