# Pre-SIP Improvements for default parameters

**URL:** <https://contributors.scala-lang.org/t/pre-sip-improvements-for-default-parameters/7367>\
**Category:** Scala Improvement Process\
**Created:** [January 30, 2026, 12:35pm UTC](https://contributors.scala-lang.org/t/pre-sip-improvements-for-default-parameters/7367 "2026-01-30T12:35:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoogeTan](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/googetan/32/3231_2.png) [@GoogeTan](https://contributors.scala-lang.org/u/GoogeTan)\
**Post date:** [January 30, 2026, 12:35pm UTC](https://contributors.scala-lang.org/t/pre-sip-improvements-for-default-parameters/7367/1 "2026-01-30T12:35:17Z")

</div>

# Summary

Currently, Context Bounds cannot be referenced inside the default values of parameters in the same method:

```scala
// No given instance of type Monad[F] was found for parameter
def foo[F[_] : Monad](something : F[Int] = summon[Monad[F]].pure(1)) : F[Int] = something
// Not found: M
def bar[F[_] : Monad as M](something : F[Int] = M.pure(1)) : F[Int] = something

```

I see two solutions:

- expand `def f[T : B](...)` to `def f[T](using B)(...)` and `def f[T : B as b](...)` to `def f[T](using b: B)(...)` correspondingly.
- add the same bounds to generated methods for default params. In case of explicit using clause it should be added to generated methods calls.

# Motivation

It is impossible to use context bonds in highly generic methods without ability to reference them.

Proposed change will make usage of context bounds more intuitive and convenient.

---

<div class="post-metadata">

**Author:** ![sjrd](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/sjrd/32/24_2.png) [@sjrd](https://contributors.scala-lang.org/u/sjrd)\
**Post date:** [January 30, 2026, 1:09pm UTC](https://contributors.scala-lang.org/t/pre-sip-improvements-for-default-parameters/7367/2 "2026-01-30T13:09:00Z")

</div>

Neither of the proposed changes is backward TASTy nor binary compatible.

You have to write the expansion yourself if you want the `using` clause first.

---

<div class="post-metadata">

**Author:** ![GoogeTan](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/googetan/32/3231_2.png) [@GoogeTan](https://contributors.scala-lang.org/u/GoogeTan)\
**Post date:** [January 30, 2026, 1:42pm UTC](https://contributors.scala-lang.org/t/pre-sip-improvements-for-default-parameters/7367/3 "2026-01-30T13:42:01Z")

</div>

What if bounds for generated methods would be added only if the bound has been used? Then old sources, as I think, will remain the same. And only usage of bounds in default params will cause no backward compatibility

---

<div class="post-metadata">

**Author:** ![Sporarum](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/sporarum/32/2545_2.png) [@Sporarum](https://contributors.scala-lang.org/u/Sporarum)\
**Post date:** [January 30, 2026, 3:54pm UTC](https://contributors.scala-lang.org/t/pre-sip-improvements-for-default-parameters/7367/4 "2026-01-30T15:54:39Z")

</div>

The other issue with putting the using parameter at the beginning is that it causes issues with type inference:

```scala
trait Bar[T]

def foo1[T](using Bar[T])(x: T) = x
def foo2[T](x: T)(using Bar[T]) = x

given Bar[Int] = ???
given Bar[String] = ???

//foo1(0) // error: Ambiguous given instances
foo2(0) // works

```

> [@GoogeTan](#):
>
> What if bounds for generated methods would be added only if the bound has been used?

I think that would work (modulo above), but it would also mean adding a default value to a parameter can sometimes cause breaking backwards compat  
(because it would move the using parameter)

IIRC @smarter proposed allowing the variable to be used before it is declared in this very specific case  
This would mean you can do things with `[T : A]` that you cannot with `(using T: A[T])`, no matter where it is placed  
which might cause trouble down the line ?

### Note:

We cannot just change the rule to “default values can refer to any parameter”, because this would lead to loops:

```scala
trait Box:
  type Value

// type of y depends of value of x, but value of x depends on y
def foo(x: Box = y)(y: x.Value)

```

However, this could never happen with `[T : A](params)`, since `A` cannot depend on `params`
