Elm Exactly
Results / elm /

ShadowingAnArgumentShadowingATopLevelValueTest

Tags:elm19-compile-errorelm-spec

Checks, in A Standard Definition of Elm?:restriction modules-no-shadowing

Not translated into Lean for the mechanisation of the book: see why.

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
A function argument with the same name as a top-level value is rejected with a SHADOWING error.

The argument of `double` is named `scale`, which is also a top-level definition in the
module; Elm does not allow a local name to shadow one already in scope.

Results

elm-0.19.1

pass
Output
Compiling ...-- SHADOWING ------------ src/ShadowingAnArgumentShadowingATopLevelValueTest.elm

The name `scale` is first defined here:

15| scale =
    ^^^^^
But then it is defined AGAIN over here:

19| double scale =
           ^^^^^
Think of a more helpful name for one of them and you should be all set!

Note: Linters advise against shadowing, so Elm makes “best practices” the
default. Read <https://elm-lang.org/0.19.1/shadowing> for more details on this
choice.

Detected problems in 1 module.

elm-0.19.2

pass
Output
Compiling ...-- SHADOWING ------------ src/ShadowingAnArgumentShadowingATopLevelValueTest.elm

The name `scale` is first defined here:

15| scale =
    ^^^^^
But then it is defined AGAIN over here:

19| double scale =
           ^^^^^
Think of a more helpful name for one of them and you should be all set!

Note: Linters advise against shadowing, so Elm makes “best practices” the
default. Read <https://elm-lang.org/0.19.2/shadowing> for more details on this
choice.

Detected problems in 1 module.

elm-0.19.3

pass
Output
Compiling ...-- SHADOWING ------------ src/ShadowingAnArgumentShadowingATopLevelValueTest.elm

The name `scale` is first defined here:

15| scale =
    ^^^^^
But then it is defined AGAIN over here:

19| double scale =
           ^^^^^
Think of a more helpful name for one of them and you should be all set!

Note: Linters advise against shadowing, so Elm makes “best practices” the
default. Read <https://elm-lang.org/0.19.3/shadowing> for more details on this
choice.

Detected problems in 1 module.

lamdera-1.5.0

pass
Output
Detected problems in 1 module.
-- SHADOWING ------------ src/ShadowingAnArgumentShadowingATopLevelValueTest.elm

The name `scale` is first defined here:

15| scale =
    ^^^^^
But then it is defined AGAIN over here:

19| double scale =
           ^^^^^
Think of a more helpful name for one of them and you should be all set!

Note: Linters advise against shadowing, so Elm makes “best practices” the
default. Read <https://elm-lang.org/0.19.3/shadowing> for more details on this
choice.

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm/ShadowingAnArgumentShadowingATopLevelValueTest] in its title.

Source

The -- CHECK: lines give the expected output.

module ShadowingAnArgumentShadowingATopLevelValueTest exposing (..)
{-| A function argument with the same name as a top-level value is rejected with a SHADOWING error.
The argument of `double` is named `scale`, which is also a top-level definition in the
module; Elm does not allow a local name to shadow one already in scope.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, modules-no-shadowing
-- COMPILE-ERROR: SHADOWING, an argument shadowing a top-level value
-- CHECK: -- SHADOWING -
scale =
2
double scale =
scale * 2
testValue =
double 3

Lean translation

No reduced program for Lean's evaluator: the test expects a compile error, so it has no meaning to evaluate. Lean has the program as written, in source syntax, and proves what the static semantics says of it (below). See the Lean mechanisation for which tests are in Lean, and why.

Static semantics: Lean proves that the program as written is not legal, so a compiler must reject it (refuse_elm_ShadowingAnArgumentShadowingATopLevelValueTest, in StandardElmMech/Certs/). The program breaks a syntactic restriction, which the kernel checks on its syntax tree; no type inference is involved (Stat.not_legal_of_modsyn): res:modules-no-shadowing. It holds for every derivation, with no hypothesis about principality.