GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [kotlin] New Rule: LocalVariableShadowsParameter · Issue #6732 · pmd/pmd

[kotlin] New Rule: LocalVariableShadowsParameter #6732

New issue
Copy link
New issue
Copy link
Closed
#6733
Closed
[kotlin] New Rule: LocalVariableShadowsParameter#6732
#6733
Copy link
Labels
a:new-ruleProposal to add a new built-in rule
Milestone
7.26.0

Description

@stokpop
stokpop
opened on May 28, 2026
Issue body actions

Proposed Rule Name: LocalVariableShadowsParameter

Proposed Category: Best Practices

Description:
Detects local variable declarations and lambda explicit parameters that shadow a parameter of any enclosing named function. Shadowing a parameter with a local variable of the same name may lead to confusion about which value is actually used.

This rule also serves as a demonstration of the new Kotlin AST features: custom AttributeView classes for typed attribute access, and KotlinAstUtil helpers for navigating the Kotlin AST.

Code Sample:

// violation - local variable 'result' shadows function parameter 'result'
fun compute(result: Int): Int {
    val result = 42
    return result
}

// no violation - different name
fun compute2(input: Int): Int {
    val result = input + 1
    return result
}

// violation - lambda explicit parameter shadows outer function parameter
fun process(result: Int): Int {
    val transform = { result: Int -> result + 1 }
    return transform(result)
}

Possible Properties:

  • No properties planned — the rule has no configurable threshold or pattern.

Not in scope / possible follow-up:

  • Local variable hiding a class field — this is a related but distinct case that requires type/classpath resolution and is better handled by a separate rule.

Related:

  • IntelliJ IDEA: "Local variable hides field" inspection
  • Kotlin detekt: NoNameShadowing
Reacted by Jeroen Borgers

Activity

  1. adangel
    added
    a:new-ruleProposal to add a new built-in rule
    on Jun 4, 2026
  2. adangel
    added this to the 7.26.0 milestone on Jun 4, 2026
  3. adangel
    added a commit that references this issue on Jun 4, 2026

    [doc] Update release notes (#6732)

    2c12b92
  4. adangel
    closed this as completedin 9da766fon Jun 4, 2026
  5. adangel
    added a commit that references this issue on Jun 4, 2026

    [kotlin] Fix pmd#6732: Add LocalVariableShadowsParameter rule (pmd#6733)

    This issue will close once commit 9da766f is merged into the 'main' branch.
    9da766f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:new-ruleProposal to add a new built-in rule

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.26.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.