diff options
author | Oscar NihlgÄrd <oscarnihlgard@gmail.com> | 2018-07-30 15:24:16 +0200 |
---|---|---|
committer | Varriount <Varriount@users.noreply.github.com> | 2018-07-30 09:24:16 -0400 |
commit | 5491f1f53b4011785b41b30897b73538d564fd55 (patch) | |
tree | a17b0e5fde1e32d6175d38cc9c7b91303e142280 | |
parent | 52807287a467dc26c7332e2574703484c02c2dba (diff) | |
download | Nim-5491f1f53b4011785b41b30897b73538d564fd55.tar.gz |
Deprecate the dot style for import paths (#8474)
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | compiler/modulepaths.nim | 1 | ||||
-rw-r--r-- | doc/manual.rst | 23 |
3 files changed, 15 insertions, 11 deletions
diff --git a/changelog.md b/changelog.md index 43b351ef1..e0027d504 100644 --- a/changelog.md +++ b/changelog.md @@ -22,6 +22,8 @@ become an error in the future. - The ``'c`` and ``'C'`` prefix for octal literals is now deprecated to bring the language in line with the standard library (e.g. ``parseOct``). +- The dot style for import paths (e.g ``import path.to.module`` instead of + ``import path/to/module``) has been deprecated. #### Breaking changes in the standard library diff --git a/compiler/modulepaths.nim b/compiler/modulepaths.nim index ef0831ad6..e5cbf3a2c 100644 --- a/compiler/modulepaths.nim +++ b/compiler/modulepaths.nim @@ -155,6 +155,7 @@ proc getModuleName*(conf: ConfigRef; n: PNode): string = # hacky way to implement 'x / y /../ z': result = renderTree(n, {renderNoComments}).replace(" ") of nkDotExpr: + localError(conf, n.info, warnDeprecated, "using '.' instead of '/' in import paths") result = renderTree(n, {renderNoComments}).replace(".", "/") of nkImportAs: result = getModuleName(conf, n.sons[0]) diff --git a/doc/manual.rst b/doc/manual.rst index 7298b02a3..abdc4ce69 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -6229,10 +6229,10 @@ imported: :test: "nim c $1" :status: 1 - import strutils except `%`, toUpper + import strutils except `%`, toUpperAscii # doesn't work then: - echo "$1" % "abc".toUpper + echo "$1" % "abc".toUpperAscii It is not checked that the ``except`` list is really exported from the module. @@ -6261,24 +6261,24 @@ A module alias can be introduced via the ``as`` keyword: echo su.format("$1", "lalelu") -The original module name is then not accessible. The -notations ``path/to/module`` or ``path.to.module`` or ``"path/to/module"`` -can be used to refer to a module in subdirectories: +The original module name is then not accessible. The notations +``path/to/module`` or ``"path/to/module"`` can be used to refer to a module +in subdirectories: .. code-block:: nim - import lib.pure.strutils, lib/pure/os, "lib/pure/times" + import lib/pure/os, "lib/pure/times" -Note that the module name is still ``strutils`` and not ``lib.pure.strutils`` +Note that the module name is still ``strutils`` and not ``lib/pure/strutils`` and so one **cannot** do: .. code-block:: nim - import lib.pure.strutils - echo lib.pure.strutils + import lib/pure/strutils + echo lib/pure/strutils.toUpperAscii("abc") Likewise the following does not make sense as the name is ``strutils`` already: .. code-block:: nim - import lib.pure.strutils as strutils + import lib/pure/strutils as strutils Collective imports from a directory @@ -6297,7 +6297,8 @@ name is not a valid Nim identifier it needs to be a string literal: Pseudo import/include paths ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -A directory can also be a so called "pseudo directory". +A directory can also be a so called "pseudo directory". They can be used to +avoid ambiguity when there are multiple modules with the same path. There are two pseudo directories: |