Skip to content

Commit 1eb3458

Browse files
committed
Expand deferred givens to lazy abstract givens
That way they can be implemented by operations of the form `given T = f(...)`, which also map to lazy values. And strict abstract values cannot be overridden by lazy values since that could undermine realizability and with it type soundness.
1 parent 9c0f648 commit 1eb3458

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ class Namer { typer: Typer =>
18271827
if !sym.maybeOwner.is(Trait) then
18281828
report.error(em"`deferred` can only be used for givens in traits", mdef.rhs.srcPos)
18291829
else
1830-
sym.resetFlag(Final | Lazy)
1830+
sym.resetFlag(Final)
18311831
sym.setFlag(Deferred | HasDefault)
18321832
case _ =>
18331833

tests/pos/deferred-givens.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import compiletime.*
2+
class Ord[Elem]
3+
4+
trait B:
5+
type Elem
6+
given Ord[Elem] = deferred
7+
def foo = summon[Ord[Elem]]
8+
9+
class C extends B:
10+
type Elem = String
11+
given Ord[Elem] = ???

0 commit comments

Comments
 (0)