yandex / yandex/implicits

Static analyzer should error on reassigning implicit with same key in same scope

Open
#29 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
43
Forks
5
PR merge metrics
No merged PRs in 30d

Description

Problem

Currently the static analyzer allows reassigning an implicit variable with the same key in the same scope:

let scope = ImplicitScope()
defer { scope.end() }

@Implicit(\.id) var id = 10

// This should be an error - reassigning same key in same scope
@Implicit(\.id) var newId = 999

This is confusing and likely a bug.

Expected Behavior

The static analyzer should emit an error when the same implicit key is assigned twice in the same scope.

Correct Pattern for Overriding

To override implicit values, use a nested scope in a separate function:

func entry() {
  let scope = ImplicitScope()
  defer { scope.end() }

  @Implicit(\.id) var id = 10
  
  doWork(scope)
}

func doWork(_ scope: ImplicitScope) {
  let scope = scope.nested()
  defer { scope.end() }

  @Implicit(\.id) var overriddenId = 999
  // ...
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test entry point is named. Start by locating the Swift static analyzer logic that validates @Implicit keys, then reproduce the two declarations in the issue's same-scope example. Done means the analyzer emits an error for duplicate keys in one scope while still allowing the nested-scope pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.