diff --git a/.github/styles/config/vocabularies/Custom/accept.txt b/.github/styles/config/vocabularies/Custom/accept.txt index b2ac2fdbc..1885313f9 100644 --- a/.github/styles/config/vocabularies/Custom/accept.txt +++ b/.github/styles/config/vocabularies/Custom/accept.txt @@ -18,3 +18,4 @@ inlined [Ii]nlining [Ss]ubgraph [Aa]pplication +[Ff]orma(e)? diff --git a/src/main/resources/org/eolang/lints/design/package-member-without-void.xsl b/src/main/resources/org/eolang/lints/design/package-member-without-void.xsl new file mode 100644 index 000000000..285d44b45 --- /dev/null +++ b/src/main/resources/org/eolang/lints/design/package-member-without-void.xsl @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + warning + The package member + + does not declare any void attributes, so it can never be reached in the implicit (receiver) form, only through the package namespace + + + + + + diff --git a/src/main/resources/org/eolang/motives/design/package-member-without-void.md b/src/main/resources/org/eolang/motives/design/package-member-without-void.md new file mode 100644 index 000000000..4906cbd81 --- /dev/null +++ b/src/main/resources/org/eolang/motives/design/package-member-without-void.md @@ -0,0 +1,36 @@ +# Package member without void + +A member of a package is also implicitly a method of any object whose forma +matches the package name. `bytes.as-number x` and `x.as-number` reach the +same `Φ.bytes.as-number` object, because the runtime binds the receiver into +the member's first void attribute when the implicit, dotted form is used. + +A member that declares no void attributes has no slot for that receiver. +The implicit form fails at runtime then, even though the explicit, +package-qualified form works fine. + +Incorrect: + +```eo ++package bytes + +# As number. +[] > as-number +``` + +Correct: + +```eo ++package bytes + +# As number. +[b] > as-number +``` + +Only top-level objects of a file that declares `+package` are checked. A +void-less formation is fine everywhere else: a ready-made constant such as +`[] > stdin`, or a local helper nested inside another formation's body. + +See [objectionary/lints#1170] for the discussion that motivated this lint. + +[objectionary/lints#1170]: https://github.com/objectionary/lints/issues/1170 diff --git a/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/allows-nested-void-less-formation.yaml b/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/allows-nested-void-less-formation.yaml new file mode 100644 index 000000000..41fe04bcc --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/allows-nested-void-less-formation.yaml @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com +# SPDX-License-Identifier: MIT +--- +sheets: + - /org/eolang/lints/design/package-member-without-void.xsl +defects: 0 +input: | + +package foo + + # Bar. + [x] > bar + # Baz. + [] > baz diff --git a/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/allows-package-member-with-void.yaml b/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/allows-package-member-with-void.yaml new file mode 100644 index 000000000..31687c72f --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/allows-package-member-with-void.yaml @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com +# SPDX-License-Identifier: MIT +--- +sheets: + - /org/eolang/lints/design/package-member-without-void.xsl +defects: 0 +input: | + +package foo + + # Bar. + [x] > bar diff --git a/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/allows-void-less-formation-without-package.yaml b/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/allows-void-less-formation-without-package.yaml new file mode 100644 index 000000000..8d9063e43 --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/allows-void-less-formation-without-package.yaml @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com +# SPDX-License-Identifier: MIT +--- +sheets: + - /org/eolang/lints/design/package-member-without-void.xsl +defects: 0 +input: | + # Stdin. + [] > stdin diff --git a/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/catches-atom-package-member-without-void.yaml b/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/catches-atom-package-member-without-void.yaml new file mode 100644 index 000000000..705cf4554 --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/catches-atom-package-member-without-void.yaml @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com +# SPDX-License-Identifier: MIT +--- +sheets: + - /org/eolang/lints/design/package-member-without-void.xsl +asserts: + - /defects[count(defect[@severity='warning'])=1] + - /defects/defect[@line='4'] +input: | + +package foo + + # Bar. + [] > bar /number diff --git a/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/catches-only-top-level-member.yaml b/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/catches-only-top-level-member.yaml new file mode 100644 index 000000000..c71d5cc94 --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/catches-only-top-level-member.yaml @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com +# SPDX-License-Identifier: MIT +--- +sheets: + - /org/eolang/lints/design/package-member-without-void.xsl +asserts: + - /defects[count(defect[@severity='warning'])=1] + - /defects/defect[@line='4'] +input: | + +package foo + + # Bar. + [] > bar + # Baz. + [] > baz diff --git a/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/catches-package-member-without-void.yaml b/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/catches-package-member-without-void.yaml new file mode 100644 index 000000000..c1d186e5f --- /dev/null +++ b/src/test/resources/org/eolang/lints/packs/single/package-member-without-void/catches-package-member-without-void.yaml @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com +# SPDX-License-Identifier: MIT +--- +sheets: + - /org/eolang/lints/design/package-member-without-void.xsl +asserts: + - /defects[count(defect[@severity='warning'])=1] + - /defects/defect[@line='4'] +input: | + +package foo + + # Bar. + [] > bar