optics-dev / optics-dev/Monocle

unused local definition warning when defining focus inside a function

Open
#1,484 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
1.7k
Forks
207
Avg merge
7h 59m
Merged PRs (30d)
5

Description

case class Lecturer(firstName: String, lastName: String, salary: Int)
case class Department(budget: Int, lecturers: List[Lecturer])
case class University(name: String, departments: Map[String, Department])

val uni = University("oxford", Map(
  "Computer Science" -> Department(45, List(
    Lecturer("john"  , "doe", 10),
    Lecturer("robert", "johnson", 16)
  )),
  "History" -> Department(30, List(
    Lecturer("arnold", "stones", 20)
  ))
))

import monocle.Focus
import monocle.syntax.all._

val departmentsWorks = Focus[University](_.departments)
departmentsWorks.at("History").replace(None)(uni)

def foo() = {

  //warning unused local definition
  val departments = Focus[University](_.departments)
  departments.at("History").replace(None)(uni)
}

foo()

Scastie: https://scastie.scala-lang.org/TfVaZDtKSmKGrgQuI7N3Rg

versions:
scala 3.5.2
monocle 3.3.0

Contributor guide

No contributing guide indexed for this repository

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

Start with the Scastie reproducer and compare the top-level FocusUniversity definition with the same definition inside foo(). Check how the local definition is expanded or inferred in Scala 3. Done means the valid local use no longer produces an unused local definition warning, while the existing optic behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.