Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1987,10 +1987,12 @@ object desugar {
.collect:
case vd: ValDef => vd

def makeContextualFunction(formals: List[Tree], paramNamesOrNil: List[TermName], body: Tree, erasedParams: List[Boolean])(using Context): Function =
def makeContextualFunction(formals: List[Tree], paramNamesOrNil: List[TermName], body: Tree, erasedParams: List[Boolean], augmenting: Boolean = false)(using Context): Function =
val paramNames =
if paramNamesOrNil.nonEmpty then paramNamesOrNil
else formals.map(_ => ContextFunctionParamName.fresh())
if paramNamesOrNil.nonEmpty then
if augmenting then paramNamesOrNil.map(ContextFunctionParamName.fresh(_))
else paramNamesOrNil
else List.fill(formals.length)(ContextFunctionParamName.fresh())
val params = for (tpt, pname) <- formals.zip(paramNames) yield
ValDef(pname, tpt, EmptyTree).withFlags(Given | Param)
FunctionWithMods(params, body, Modifiers(Given), erasedParams)
Expand Down
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/core/NameKinds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,18 @@ object NameKinds {
/** The name of an inferred contextual function parameter:
*
* val x: A ?=> B = b
* val f: (x: A) ?=> B = b
*
* becomes:
*
* val x: A ?=> B = (contextual$1: A) ?=> b
* val f: (x: A) ?=> B = (xcontextual$1: A) ?=> b
*/
val ContextFunctionParamName: UniqueNameKind = new UniqueNameKind("contextual$")
val ContextFunctionParamName: UniqueNameKind =
new UniqueNameKind("contextual$"):
override def mkString(underlying: TermName, info: ThisInfo): String =
if !underlying.isEmpty then str.sanitize(underlying.toString)
else separator + info.num

/** Other unique names */
val CanThrowEvidenceName: UniqueNameKind = new UniqueNameKind("canThrow$")
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Names.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ object Names {
def info: NameInfo = SimpleNameKind.info
def underlying: TermName = unsupported("underlying")

@sharable // because of synchronized block in `and`
@sharable // because of synchronized block in `add`
private var derivedNames: LinearMap[NameInfo, DerivedName] = LinearMap.empty

private def add(info: NameInfo): TermName = synchronized {
Expand Down
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
case tp: LazyRef =>
def refTxt =
try toTextGlobal(tp.ref)
catch {
case ex: Throwable => Str("...")
}
catch case _: Throwable => Str("...") // reconsider catching errors
"LazyRef(" ~ refTxt ~ ")"
case Range(lo, hi) =>
toText(lo) ~ ".." ~ toText(hi)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3912,7 +3912,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
case _ => paramTypes.map(_ => false)
}

val ifun = desugar.makeContextualFunction(paramTypes, paramNamesOrNil, tree, erasedParams)
val ifun = desugar.makeContextualFunction(paramTypes, paramNamesOrNil, tree, erasedParams, augmenting = true)
typr.println(i"make contextual function $tree / $pt ---> $ifun")
typedFunctionValue(ifun, pt)
.tap:
Expand Down
6 changes: 4 additions & 2 deletions tests/neg-custom-args/captures/filevar.check
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
|The leakage occurred when trying to match the following types:
|
|Found: (l: scala.caps.Capability^) ?->'s2 File^'s3 ->'s4 Unit
|Required: (l: scala.caps.Capability^) ?-> (f: File^{l}) => Unit
|Required: (l²: scala.caps.Capability^) ?-> (f: File^{l²}) => Unit
|
|where: => refers to a root capability associated with the result type of (using l: scala.caps.Capability^): (f: File^{l}) => Unit
|where: => refers to a root capability associated with the result type of (using l²: scala.caps.Capability^): (f: File^{l²}) => Unit
| ^ refers to the universal root capability
| l is a reference to a value parameter
| l² is a reference to a value parameter
16 | val o = Service()
17 | o.file = f
18 | o.log
Expand Down
10 changes: 6 additions & 4 deletions tests/neg-custom-args/captures/i15923.check
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
|The leakage occurred when trying to match the following types:
|
|Found: (lcap: scala.caps.Capability^) ?->'s2 Cap^'s3 ->'s4 Id[Cap^'s5]^'s6
|Required: (lcap: scala.caps.Capability^) ?-> Cap^{lcap} => Id[Cap^'s1]^'s7
|Required: (lcap²: scala.caps.Capability^) ?-> Cap^{lcap²} => Id[Cap^'s1]^'s7
|
|where: => refers to a root capability associated with the result type of (using lcap: scala.caps.Capability^): Cap^{lcap} => Id[Cap^'s1]^'s7
| ^ refers to the universal root capability
| cap is a root capability associated with the result type of (x$0: Cap^'s3): Id[Cap^'s5]^'s6
|where: => refers to a root capability associated with the result type of (using lcap²: scala.caps.Capability^): Cap^{lcap²} => Id[Cap^'s1]^'s7
| ^ refers to the universal root capability
| cap is a root capability associated with the result type of (x$0: Cap^'s3): Id[Cap^'s5]^'s6
| lcap is a reference to a value parameter
| lcap² is a reference to a value parameter
|
| longer explanation available when compiling with `-explain`
4 changes: 2 additions & 2 deletions tests/neg-custom-args/captures/lazyvals2.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals2.scala:19:31 ------------------------------------
19 | val fun2: () ->{io} String = () => x() // error
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals2.scala:20:31 ------------------------------------
20 | val fun2: () ->{io} String = () => x() // error
| ^^^^^^^^^
| Found: () ->{console, io} String
| Required: () ->{io} String
Expand Down
1 change: 1 addition & 0 deletions tests/neg-custom-args/captures/lazyvals2.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//> using options -Yimports:scala,scala.Predef
import language.experimental.captureChecking
import caps.*

Expand Down
28 changes: 14 additions & 14 deletions tests/neg-custom-args/captures/lazyvals5.check
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:31:41 ------------------------------------
31 | val v0: () -> () ->{io} String = () => t.memberLazy // error
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:32:41 ------------------------------------
32 | val v0: () -> () ->{io} String = () => t.memberLazy // error
| ^^^^^^^^^^^^^^^^^^
| Found: () ->{t} () ->{io} String
| Required: () -> () ->{io} String
|
| Note that capability t is not included in capture set {}.
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:33:41 ------------------------------------
33 | val v1: () -> String = () => t.memberLazy() // error
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:34:41 ------------------------------------
34 | val v1: () -> String = () => t.memberLazy() // error
| ^^^^^^^^^^^^^^^^^^^^
| Found: () ->{t} String
| Required: () -> String
|
| Note that capability t is not included in capture set {}.
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:35:41 ------------------------------------
35 | val v3: (() -> String)^{c.console} = () => c.memberLazy() // error (but should this be allowed?)
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:36:41 ------------------------------------
36 | val v3: (() -> String)^{c.console} = () => c.memberLazy() // error (but should this be allowed?)
| ^^^^^^^^^^^^^^^^^^^^
| Found: () ->{c} String
| Required: () ->{c.console} String
|
| Note that capability c is not included in capture set {c.console}.
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:36:41 ------------------------------------
36 | val v4: () -> String = () => t.memberMethod() // error
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:37:41 ------------------------------------
37 | val v4: () -> String = () => t.memberMethod() // error
| ^^^^^^^^^^^^^^^^^^^^^^
| Found: () ->{t} String
| Required: () -> String
|
| Note that capability t is not included in capture set {}.
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:39:28 ------------------------------------
39 | val v6: () ->{c} String = () => funky // error
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:40:28 ------------------------------------
40 | val v6: () ->{c} String = () => funky // error
| ^^^^^^^^^^^
| Found: () ->{t, c} String
| Required: () ->{c} String
|
| Note that capability t is not included in capture set {c}.
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:40:30 ------------------------------------
40 | val v6_1: () ->{t} String = () => funky // error
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:41:30 ------------------------------------
41 | val v6_1: () ->{t} String = () => funky // error
| ^^^^^^^^^^^
| Found: () ->{t, c} String
| Required: () ->{t} String
|
| Note that capability c is not included in capture set {t}.
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:60:55 ------------------------------------
60 | val v9: () ->{c2.memberLazy, t2.memberLazy} String = () => funky2 // error (but should this be allowed?)
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals5.scala:61:55 ------------------------------------
61 | val v9: () ->{c2.memberLazy, t2.memberLazy} String = () => funky2 // error (but should this be allowed?)
| ^^^^^^^^^^^^
| Found: () ->{t2, c2} String
| Required: () ->{c2.memberLazy, t2.memberLazy²} String
Expand Down
3 changes: 2 additions & 1 deletion tests/neg-custom-args/captures/lazyvals5.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//> using options -Yimports:scala,scala.Predef
import language.experimental.captureChecking
import caps.*

Expand Down Expand Up @@ -60,4 +61,4 @@ def client(c: Clazz^): Unit =
val v9: () ->{c2.memberLazy, t2.memberLazy} String = () => funky2 // error (but should this be allowed?)
val v10: () ->{t2, c2} String = () => funky2 // ok

()
()
68 changes: 34 additions & 34 deletions tests/neg-custom-args/captures/scope-extrusions.check
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:9:8 -------------------------------
9 | v = x // error
| ^
| Found: (x : IO)
| Required: IO^
|
| Note that capability x is not included in capture set {cap}
| because (x : IO) in method f1 is not visible from cap in variable v.
|
| where: ^ and cap refer to a fresh root capability classified as SharedCapability in the type of variable v
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:10:8 ------------------------------
10 | w = g // error
10 | v = x // error
| ^
| Found: (x : IO)
| Required: IO^
|
| Note that capability x is not included in capture set {cap}
| because (x : IO) in method f1 is not visible from cap in variable v.
|
| where: ^ and cap refer to a fresh root capability classified as SharedCapability in the type of variable v
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:11:8 ------------------------------
11 | w = g // error
| ^
| Found: () ->{x} Unit
| Required: () => Unit
Expand All @@ -22,8 +22,8 @@
| where: => and cap refer to a fresh root capability in the type of variable w
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:19:11 -----------------------------
19 | withFile(io => io) // error
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:20:11 -----------------------------
20 | withFile(io => io) // error
| ^^^^^^^^
|Capability io outlives its scope: it leaks into outer capture set 's1 which is owned by method test.
|The leakage occurred when trying to match the following types:
Expand All @@ -35,8 +35,8 @@
| ^ refers to the universal root capability
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:20:11 -----------------------------
20 | withFile(id) // error
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:21:11 -----------------------------
21 | withFile(id) // error
| ^^
|Capability x outlives its scope: it leaks into outer capture set 's4 which is owned by method test.
|The leakage occurred when trying to match the following types:
Expand All @@ -48,8 +48,8 @@
| ^ refers to the universal root capability
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:21:11 -----------------------------
21 | withFile(x => id(x)) // error
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:22:11 -----------------------------
22 | withFile(x => id(x)) // error
| ^^^^^^^^^^
|Capability x outlives its scope: it leaks into outer capture set 's6 which is owned by method test.
|The leakage occurred when trying to match the following types:
Expand All @@ -61,8 +61,8 @@
| ^ refers to the universal root capability
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:22:11 -----------------------------
22 | withFile(id2) // error, note mentions cap since we never have a more specific include failure
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:23:11 -----------------------------
23 | withFile(id2) // error, note mentions cap since we never have a more specific include failure
| ^^^
|Capability cap outlives its scope: it leaks into outer capture set 's9 which is owned by method test.
|The leakage occurred when trying to match the following types:
Expand All @@ -76,8 +76,8 @@
| cap is a root capability associated with the result type of (x: IO^): IO^'s9
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:23:11 -----------------------------
23 | withFile(x => id2(x)) // error, note mentions cap since we never have a more specific include failure
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:24:11 -----------------------------
24 | withFile(x => id2(x)) // error, note mentions cap since we never have a more specific include failure
| ^^^^^^^^^^^
|Capability cap outlives its scope: it leaks into outer capture set 's11 which is owned by method test.
|The leakage occurred when trying to match the following types:
Expand All @@ -91,8 +91,8 @@
| cap is a root capability associated with the result type of (x: IO^²): IO^'s11
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:24:11 -----------------------------
24 | withFile(identity) // error, note mentions cap since we never have a more specific include failure
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:25:11 -----------------------------
25 | withFile(identity) // error, note mentions cap since we never have a more specific include failure
| ^^^^^^^^
|Capability cap outlives its scope: it leaks into outer capture set 's14 which is owned by method test.
|The leakage occurred when trying to match the following types:
Expand All @@ -105,8 +105,8 @@
| cap is a root capability associated with the result type of (x: IO^): IO^'s14
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:25:11 -----------------------------
25 | withFile(x => identity(x)) // error, note mentions cap since we never have a more specific include failure
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:26:11 -----------------------------
26 | withFile(x => identity(x)) // error, note mentions cap since we never have a more specific include failure
| ^^^^^^^^^^^^^^^^
|Capability cap outlives its scope: it leaks into outer capture set 's18 which is owned by method test.
|The leakage occurred when trying to match the following types:
Expand All @@ -119,8 +119,8 @@
| cap is a root capability associated with the result type of (x: IO^): IO^'s18
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:27:12 -----------------------------
27 | withFile: io => // error
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:28:12 -----------------------------
28 | withFile: io => // error
| ^
|Capability io outlives its scope: it leaks into outer capture set 's22 which is owned by method test.
|The leakage occurred when trying to match the following types:
Expand All @@ -130,11 +130,11 @@
|
|where: => refers to a fresh root capability created in method test when checking argument to parameter op of method withFile
| ^ refers to the universal root capability
28 | () => println(io)
29 | () => println(io)
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:30:21 -----------------------------
30 | val f2: IO => IO = (x: IO) => x // error
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:31:21 -----------------------------
31 | val f2: IO => IO = (x: IO) => x // error
| ^^^^^^^^^^^^
| Found: (x: IO^) ->'s25 IO^{x}
| Required: IO^ => IO^²
Expand All @@ -147,8 +147,8 @@
| ^² and cap refer to a fresh root capability classified as SharedCapability in the type of value f2
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:32:21 -----------------------------
32 | val f4: IO => IO = f3 // error
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrusions.scala:33:21 -----------------------------
33 | val f4: IO => IO = f3 // error
| ^^
| Found: (f3 : (x$0: IO) ->{} IO^{x$0})
| Required: IO^ => IO^²
Expand Down
Loading
Loading