Skip to content

Commit

Permalink
Drop syntax sugar for capture set member
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Nov 30, 2024
1 parent 5a901f4 commit f8893e5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/cc/CaptureRef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ trait CaptureRef extends TypeProxy, ValueType:
|| viaInfo(y.info)(subsumingRefs(this, _))
case MaybeCapability(y1) => this.stripMaybe.subsumes(y1)
case y: TypeRef if y.derivesFrom(defn.Caps_CapSet) =>
// The upper and lower bounds don't have to be in the form of `CapSet^{...}`.
// They can be other capture set variables, which are bounded by `CapSet`,
// like `def test[X^, Y^, Z >: X <: Y]`.
y.info match
case TypeBounds(_, hi: CaptureRef) => this.subsumes(hi)
case _ => y.captureSetOfInfo.elems.forall(this.subsumes)
Expand Down
7 changes: 2 additions & 5 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4057,11 +4057,8 @@ object Parsers {
|| sourceVersion.isAtLeast(`3.6`) && in.isColon =>
makeTypeDef(typeAndCtxBounds(tname))
case _ =>
if in.isIdent(nme.UPARROW) && Feature.ccEnabled then
makeTypeDef(typeAndCtxBounds(tname))
else
syntaxErrorOrIncomplete(ExpectedTypeBoundOrEquals(in.token))
return EmptyTree // return to avoid setting the span to EmptyTree
syntaxErrorOrIncomplete(ExpectedTypeBoundOrEquals(in.token))
return EmptyTree // return to avoid setting the span to EmptyTree
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-custom-args/captures/capture-poly.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import caps.*
trait Foo extends Capability

trait CaptureSet:
type C^
type C >: CapSet <: CapSet^

def capturePoly[C^](a: Foo^{C^}): Foo^{C^} = a
def capturePoly2(c: CaptureSet)(a: Foo^{c.C^}): Foo^{c.C^} = a
Expand Down
22 changes: 11 additions & 11 deletions tests/neg-custom-args/captures/i21614.check
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i21614.scala:9:33 ----------------------------------------
9 | files.map((f: F) => new Logger(f)) // error, Q: can we make this pass (see #19076)?
| ^
| Found: (f : F^)
| Required: File^
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i21614.scala:12:12 ---------------------------------------
12 | files.map(new Logger(_)) // error, Q: can we improve the error message?
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i21614.scala:12:33 ---------------------------------------
12 | files.map((f: F) => new Logger(f)) // error, Q: can we make this pass (see #19076)?
| ^
| Found: (f : F^)
| Required: File^
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i21614.scala:15:12 ---------------------------------------
15 | files.map(new Logger(_)) // error, Q: can we improve the error message?
| ^^^^^^^^^^^^^
| Found: (_$1: box File^{files*}) ->{files*} (ex$13: caps.Exists) -> box Logger{val f: File^{_$1}}^{ex$13}
| Required: (_$1: box File^{files*}) -><fluid> box Logger{val f: File^?}^?
| Found: (_$1: box File^{files*}) ->{files*} (ex$16: caps.Exists) -> box Logger{val f: File^{_$1}}^{ex$16}
| Required: (_$1: box File^{files*}) => box Logger{val f: File^?}^?
|
| Note that the universal capability `cap`
| cannot be included in capture set ?
Expand Down
3 changes: 3 additions & 0 deletions tests/neg-custom-args/captures/i21614.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import language.experimental.captureChecking
import caps.Capability
import caps.use

trait List[+T]:
def map[U](f: T => U): List[U]

trait File extends Capability
class Logger(f: File^) extends Capability // <- will work if we remove the extends clause

Expand Down
8 changes: 4 additions & 4 deletions tests/neg-custom-args/captures/i21868.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ trait AbstractWrong:
def f(): Unit^{C^} // error

trait Abstract1:
type C^
type C >: CapSet <: CapSet^
def f(): Unit^{C^}

class Abstract2:
type C >: CapSet <: CapSet^
def f(): Unit^{C^}
// class Abstract2:
// type C^
// def f(): Unit^{C^}

0 comments on commit f8893e5

Please sign in to comment.