Skip to content

extension with using clauses with defaults and with a method with default argument fails at call site #24886

@sjbiaga

Description

@sjbiaga

Compiler version

3.8.0-RC4

Minimized example

This may be a long shot, but... I have a rudimentary key-value language, where values may be keys in turn. Putting it shortly, the possible type-methods (named like boolean or int) are extension methods with receiver a String. The extension syntax employs using clauses with defaults.

For each extension method, another method is defined outside extensions with a default receiver. A "variable" is a pair (String, String).

For simplicity, the key is stored in a default: Option[String] variable.

implicit def ?[S, T](fun: S => T): S ?=> T = { it ?=> fun(it) }

case class RuntimeException2(`var`: (String, String), cause: Throwable) extends RuntimeException("" + `var` + cause.getMessage)

var default: Option[String] = Some("test")
var value: String = "0"

extension (self: String)
          (using err: String => ((String, String)) ?=> Throwable = { msg => `var` ?=> RuntimeException(msg + `var`) })
          (using key: () => String = () => default.get)
          (using `var`: (() => String) ?=> (String, String) = { key ?=> key() -> self })

  def boolean: Boolean =
    try
      self.toLowerCase.toBoolean
    catch _ => throw err("a boolean")

  def int(`type`: String = "an integer"): Int =
    try
      self.toInt
    catch _ => throw err(`type`)

  def pos: Int = int("a positive integer").abs

def boolean: Boolean = value.boolean
def int(`type`: String = "an integer"): Int = value.int(`type`) // the error is caused by this line
def pos: Int = value.pos(using { msg => RuntimeException2(_, cause = RuntimeException(msg)) })

The three using clauses in the extension work like this: given a (default) key (of type () => String), I can make a given (String, String) pair (the `var` third parameter), and then return a RuntimeException via the first err parameter.

Output Error/Warning message

-- [E081] Type Error: ----------------------------------------------------------
6 |          (using err: String => ((String, String)) ?=> Throwable = { msg => `var` ?=> RuntimeException(msg + `var`) })
  |                                                                     ^^^
  |                           Missing parameter type
  |
  |                           I could not infer the type of the parameter msg
-- [E081] Type Error: ----------------------------------------------------------
6 |          (using err: String => ((String, String)) ?=> Throwable = { msg => `var` ?=> RuntimeException(msg + `var`) })
  |                                                                            ^^^^^
  |                           Missing parameter type
  |
  |                           I could not infer the type of the parameter var
-- [E081] Type Error: ----------------------------------------------------------
8 |          (using `var`: (() => String) ?=> (String, String) = { key ?=> key() -> self })
  |                                                                ^^^
  |                           Missing parameter type
  |
  |                           I could not infer the type of the parameter key
-- [E008] Not Found Error: -----------------------------------------------------
19 |def int(`type`: String = "an integer"): Int = value.int(`type`)
   |                                              ^^^^^^^^^
   |value int is not a member of String.
   |An extension method was tried, but could not be fully constructed:
   |
   |    {
   |      val self$2: String = value
   |      val err$2:
   |        
   |          <error Missing parameter type
   |    
   |    I could not infer the type of the parameter msg>
   |           => (
   |          <error Missing parameter type
   |    
   |    I could not infer the type of the parameter var>
   |          ) ?=> <error unspecified error>
   |       = this.int$default$2(self$2)
   |      val key$2: () => String = this.int$default$3(self$2)(err$2)
   |      int(self$2)(using err$2)(using key$2)(using (using contextual$3: () => String)
   |         =>
   |        this.int$default$4(self$2)(err$2)(key$2).apply(/* missing */summon[<notype>]
   |          )
   |      )
   |    }
   |
   |    failed with:
   |
   |        No given instance of type <error Missing parameter type
   |        
   |        I could not infer the type of the parameter key> was found for parameter of (<error Missing parameter type
   |        
   |        I could not infer the type of the parameter key>
   |          ) ?=> <error unspecified error>
-- Error: ----------------------------------------------------------------------
19 |def int(`type`: String = "an integer"): Int = value.int(`type`)
   |    ^
   |    two or more overloaded variants of method int have default arguments
there was 1 feature warning; re-run with -feature for details
1 warning found
5 errors found

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:reportingError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancementstat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions