Skip to content

Description of given instances in error messages is too low-level #11066

Closed
@odersky

Description

@odersky

This code:

class PreferredPrompt(val preference: String)
object Greeter:
  def greet(name: String)(using prompt: PreferredPrompt) =
    println(s"Welcome, $name. The system is ready.")
    println(prompt.preference)
object JillsPrefs:
  given jillsPrompt: PreferredPrompt =
    PreferredPrompt("Your wish> ")
object JoesPrefs:
  given joesPrompt: PreferredPrompt =
    PreferredPrompt("relax> ")

import JillsPrefs.jillsPrompt
import JoesPrefs.joesPrompt
val x = Greeter.greet("Who's there?") // error

gives this error message:

-- Error: i11066.scala:15:37 ---------------------------------------------------
15 |val x = Greeter.greet("Who's there?")
   |                                     ^
   |ambiguous implicit arguments: both lazy value joesPrompt in object JoesPrefs and lazy value jillsPrompt in object JillsPrefs match type PreferredPrompt of parameter prompt of method greet in object Greeter

Expected

A description of JoesPrefs and JillsPrefs as given instances, not lazy vals. Lazy vals reveals underlying implementation details that should be omitted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:reportingError reporting including formatting, implicit suggestions, etcitype:enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions