Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule 6.2.2: there should be no extension functions with the same name and signature if they extend base and inheritor classes (possible_bug) #447

Closed
petertrr opened this issue Oct 23, 2020 · 0 comments · Fixed by #501
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@petertrr
Copy link
Member

As extension functions are resolved statically. In this case there can be a situation when a developer implements two extension functions - one is for the base class and another one for the inheritor.
And that can lead to an issue when incorrect method is used.
Bad example:

open class A
class B: A()

// two extension functions with the same signature
fun A.foo() = "A"
fun B.foo() = "B"

fun printClassName(s: A) { println(s.foo()) }

// this call will run foo() method from the base class A, but
// programmer can expect to run foo() from the class inheritor B
fun main() { printClassName(B()) }
@petertrr petertrr added the enhancement New feature or request label Oct 23, 2020
@petertrr petertrr added this to the Chapter 6 milestone Oct 23, 2020
@aktsay6 aktsay6 self-assigned this Nov 6, 2020
aktsay6 added a commit that referenced this issue Nov 6, 2020
### What's done:
  * Added rule logic
  * Added warn tests
aktsay6 added a commit that referenced this issue Nov 7, 2020
### What's done:
  * Added rule logic
  * Added warn tests
aktsay6 added a commit that referenced this issue Nov 7, 2020
### What's done:
  * Added rule logic
  * Added warn tests
@aktsay6 aktsay6 mentioned this issue Nov 7, 2020
5 tasks
aktsay6 added a commit that referenced this issue Nov 10, 2020
# Conflicts:
#	diktat-analysis.yml
#	diktat-rules/src/main/kotlin/generated/WarningNames.kt
#	diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt
#	diktat-rules/src/main/resources/diktat-analysis-huawei.yml
#	diktat-rules/src/main/resources/diktat-analysis.yml
#	info/available-rules.md
aktsay6 added a commit that referenced this issue Nov 10, 2020
### What's done:
  * Fixed bugs
aktsay6 added a commit that referenced this issue Nov 16, 2020
# Conflicts:
#	diktat-analysis.yml
#	diktat-rules/src/main/kotlin/generated/WarningNames.kt
#	diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt
#	diktat-rules/src/main/resources/diktat-analysis-huawei.yml
#	diktat-rules/src/main/resources/diktat-analysis.yml
#	info/available-rules.md
aktsay6 added a commit that referenced this issue Nov 16, 2020
### What's done:
  * Merged master in current branch
aktsay6 added a commit that referenced this issue Nov 16, 2020
### What's done:
  * Fixed bugs
aktsay6 added a commit that referenced this issue Nov 16, 2020
* feature/rule-6.2.2(#447)
### What's done:
  * Added rule logic
  * Added warn tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants