Skip to content

Commit 3498ec5

Browse files
oderskyallanrenucci
authored andcommitted
Refinements to soft modifiers
- also handle parameter modifiers - add a spec
1 parent 1762b0e commit 3498ec5

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,8 @@ object Parsers {
19551955
}
19561956
}
19571957
else {
1958-
if (isIdent(nme.`inline`)) mods = addModifier(mods)
1958+
if (isIdent(nme.`inline`) && in.isSoftModifierInParamModifierPosition)
1959+
mods = addModifier(mods)
19591960
mods = atPos(start) { mods | Param }
19601961
}
19611962
atPos(start, nameStart) {
@@ -2614,7 +2615,7 @@ object Parsers {
26142615
if (in.token == IMPLICIT || in.token == ERASED) {
26152616
val start = in.offset
26162617
var imods = modifiers(funArgMods)
2617-
if (isBindingIntro && !isIdent(nme.`inline`))
2618+
if (isBindingIntro)
26182619
stats += implicitClosure(start, Location.InBlock, imods)
26192620
else
26202621
stats +++= localDef(start, imods)

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,9 @@ object Scanners {
742742
def isSoftModifierInModifierPosition: Boolean =
743743
isSoftModifier && inModifierPosition()
744744

745+
def isSoftModifierInParamModifierPosition: Boolean =
746+
isSoftModifier && !lookaheadIn(BitSet(COLON))
747+
745748
// Literals -----------------------------------------------------------------
746749

747750
private def getStringLit() = {

docs/docs/reference/inline.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ layout: doc-page
33
title: Inline
44
---
55

6-
`inline` is a new modifier that guarantees that a definition will be
7-
inline at the point of use. Example:
6+
`inline` is a new [soft modifier](./soft-modifier.html) that guarantees that a definition will be inline at the point of use. Example:
87

98
object Config {
109
inline val logging = false

docs/docs/reference/opaques.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ But the following operations would lead to type errors:
5353
l / l2 // error: `/` is not a member fo Logarithm
5454
```
5555

56+
`opaque` is a [soft modifier](./soft-modifier.html).
57+
5658
For more details, see [Scala SIP 35](https://docs.scala-lang.org/sips/opaque-types.html).

tests/pos/i5145.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@ class Test {
55
opaque(3)
66
inline
77
}
8+
def bar(inline: Int => Int) = 3
9+
inline def baz(inline x: Int => Int) = 3
10+
11+
locally {
12+
bar(inline = identity)
13+
bar(inline => inline)
14+
bar(implicit inline => inline)
15+
}
816
}

0 commit comments

Comments
 (0)