On 28.07.2017 23:30, FoxyBrown wrote:

because you didn't want to spend 10 minutes to fix a program.

You need to realize that the same thing applies to you. There is no "us" vs "you". I.e. if you know it to only be 10 minutes of work, why don't you just fix it yourself? Mike currently has as many commits in DMD as you do, and he is already busy contributing in other ways.

The compiler is here: https://github.com/dlang/dmd

Just implement the check, and commit it with commit message "fix Issue 17699 - Importing a module that has both modulename.d and modulename/package.d should be an error", then create a pull request.

It is very easy to figure out where to add the check:

$ git clone g...@github.com:dlang/dmd
$ cd dmd/src/ddmd$
$ grep "package.d" * # the obvious string to search for
access.d:                printf("\ts is in same package.d module as sc\n");
astbase.d: PKGunknown, // not yet determined whether it's a package.d or not astbase.d: PKGmodule, // already determined that's an actual package.d
grep: backend: Is a directory
dimport.d: // mod is a package.d, or a normal module which conflicts with the package name.
dmodule.d:         * Therefore, the result should be: filename/package.d
dmodule.d:         * iff filename/package.d is a file
dmodule.d: const(char)* ni = FileName.combine(filename, "package.di");
dmodule.d:        const(char)* n = FileName.combine(filename, "package.d");
dmodule.d:            const(char)* n2i = FileName.combine(n, "package.di");
dmodule.d:            const(char)* n2 = FileName.combine(n, "package.d");
dmodule.d: PKGunknown, // not yet determined whether it's a package.d or not dmodule.d: PKGmodule, // already determined that's an actual package.d
dmodule.d:    bool isPackageFile;         // if it is a package.d
dmodule.d: // if module is not named 'package' but we're trying to read 'package.d', we're looking for a package module dmodule.d: bool isPackageMod = (strcmp(toChars(), "package") != 0) && (strcmp(srcfile.name.name(), "package.d") == 0 || (strcmp(srcfile.name.name(), "package.di") == 0)); dmodule.d: .error(loc, "importing package '%s' requires a 'package.d' file which cannot be found in '%s'", toChars(), srcfile.toChars()); dmodule.d: isPackageFile = (strcmp(srcfile.name.name(), "package.d") == 0 || dmodule.d: strcmp(srcfile.name.name(), "package.di") == 0); dmodule.d: if (m && (strcmp(m.srcfile.name.name(), "package.d") != 0 && dmodule.d: strcmp(m.srcfile.name.name(), "package.di") != 0))
dmodule.d:             *     +- package.d
dmodule.d: * If both are used in one compilation, 'pkg' as a module (== pkg/package.d) dmodule.d: * later package.d loading will change Package::isPkgMod to PKGmodule and set Package::mod. dmodule.d: * 2. Otherwise, 'package.d' wrapped by 'Package' is inserted to the internal tree in here. dmodule.d: /* If the previous inserted Package is not yet determined as package.d, module.h: PKGunknown, // not yet determined whether it's a package.d or not
module.h:    PKGmodule,  // already determined that's an actual package.d
module.h:    bool isPackageFile; // if it is a package.d


I.e., let's check out dmodule.d. We immediately find the following code:

extern (C++) const(char)* lookForSourceFile(const(char)** path, const(char)* filename)
{
    *path = null;
    /* Search along global.path for .di file, then .d file.
     */
    const(char)* sdi = FileName.forceExt(filename, global.hdr_ext);
    if (FileName.exists(sdi) == 1)
        return sdi;
    const(char)* sd = FileName.forceExt(filename, global.mars_ext);
    if (FileName.exists(sd) == 1)
        return sd;
    if (FileName.exists(filename) == 2)
    {
        /* The filename exists and it's a directory.
         * Therefore, the result should be: filename/package.d
         * iff filename/package.d is a file
         */
        const(char)* ni = FileName.combine(filename, "package.di");
        if (FileName.exists(ni) == 1)
            return ni;
        FileName.free(ni);
        const(char)* n = FileName.combine(filename, "package.d");
        if (FileName.exists(n) == 1)
            return n;
        FileName.free(n);
    }
    ...


I'll let you (or anyone else who would like to) take it from here.


              • Re:... Anonymouse via Digitalmars-d-learn
              • Re:... FoxyBrown via Digitalmars-d-learn
              • Re:... Grander via Digitalmars-d-learn
              • Re:... Joakim via Digitalmars-d-learn
              • Re:... FoxyBrown via Digitalmars-d-learn
              • Re:... Adam D. Ruppe via Digitalmars-d-learn
              • Re:... FoxyBrown via Digitalmars-d-learn
              • Re:... Joakim via Digitalmars-d-learn
              • Re:... Jonathan M Davis via Digitalmars-d-learn
              • Re:... FoxyBrown via Digitalmars-d-learn
              • Re:... Timon Gehr via Digitalmars-d-learn
              • Re:... FoxyBrown via Digitalmars-d-learn
              • Re:... Timon Gehr via Digitalmars-d-learn
              • Re:... Grander via Digitalmars-d-learn
              • Re:... Jonathan M Davis via Digitalmars-d-learn
              • Re:... Steven Schveighoffer via Digitalmars-d-learn
              • Re:... Ali Çehreli via Digitalmars-d-learn
              • Re:... Steven Schveighoffer via Digitalmars-d-learn
              • Re:... Ali Çehreli via Digitalmars-d-learn
              • Re:... Steven Schveighoffer via Digitalmars-d-learn
  • Re: It makes me sick! Jesse Phillips via Digitalmars-d-learn

Reply via email to