Skip to content

Tweaks to indent syntax #7363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -832,11 +832,12 @@ object SymDenotations {
| Access to protected $this not permitted because enclosing ${ctx.owner.enclosingClass.showLocated}
| is not a subclass of ${owner.showLocated} where target is defined""")
else if
(!( isType // allow accesses to types from arbitrary subclasses fixes #4737
!( isType // allow accesses to types from arbitrary subclasses fixes #4737
|| pre.derivesFrom(cls)
|| isConstructor
|| owner.is(ModuleClass) // don't perform this check for static members
))
)
then
fail(
i"""
| Access to protected ${symbol.show} not permitted because prefix type ${pre.widen.show}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Tokens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ object Tokens extends TokensCommon {
final val closingRegionTokens = BitSet(RBRACE, CASE) | statCtdTokens

final val canStartIndentTokens: BitSet =
statCtdTokens | BitSet(COLONEOL, EQUALS, ARROW, LARROW, WHILE, TRY, FOR)
statCtdTokens | BitSet(COLONEOL, EQUALS, ARROW, LARROW, WHILE, TRY, FOR, RETURN, IF)
// `if` is excluded because it often comes after `else` which makes for awkward indentation rules TODO: try to do without the exception

/** Faced with the choice between a type and a formal parameter, the following
Expand Down
28 changes: 14 additions & 14 deletions docs/docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,22 @@ Ascription ::= ‘:’ InfixType
Catches ::= ‘catch’ Expr
PostfixExpr ::= InfixExpr [id] PostfixOp(expr, op)
InfixExpr ::= PrefixExpr
| InfixExpr id [cnl] InfixExpr InfixOp(expr, op, expr)
| InfixExpr id [nl] InfixExpr InfixOp(expr, op, expr)
| InfixExpr ‘given’ (InfixExpr | ParArgumentExprs)
PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr PrefixOp(expr, op)
SimpleExpr ::= ‘new’ (ConstrApp [TemplateBody] | TemplateBody) New(constr | templ)
SimpleExpr ::= Path
| Literal
| ‘_’
| BlockExpr
| ‘$’ ‘{’ Block ‘}’
| Quoted
| quoteId // only inside splices
| SimpleExpr1 [‘_’] PostfixOp(expr, _)
SimpleExpr1 ::= Literal
| Path
| ‘_’
| ‘new’ (ConstrApp [TemplateBody] | TemplateBody) New(constr | templ)
| ‘(’ ExprsInParens ‘)’ Parens(exprs)
| SimpleExpr ‘.’ id Select(expr, id)
| SimpleExpr (TypeArgs | NamedTypeArgs) TypeApply(expr, args)
| SimpleExpr1 ArgumentExprs Apply(expr, args)
| SimpleExpr TypeArgs TypeApply(expr, args)
| SimpleExpr ArgumentExprs Apply(expr, args)
| SimpleExpr ‘_’ PostfixOp(expr, _)
| XmlExpr
Quoted ::= ‘'’ ‘{’ Block ‘}’
| ‘'’ ‘[’ Type ‘]’
Expand All @@ -234,8 +234,8 @@ ExprInParens ::= PostfixExpr ‘:’ Type
ParArgumentExprs ::= ‘(’ [‘given’] ExprsInParens ‘)’ exprs
| ‘(’ [ExprsInParens ‘,’] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ exprs :+ Typed(expr, Ident(wildcardStar))
ArgumentExprs ::= ParArgumentExprs
| [cnl] BlockExpr
BlockExpr ::= ‘{’ CaseClauses | Block ‘}’
| [nl] BlockExpr
BlockExpr ::= ‘{’ (CaseClauses | Block) ‘}’
Block ::= {BlockStat semi} [BlockResult] Block(stats, expr?)
BlockStat ::= Import
| {Annotation [nl]} [‘implicit’ | ‘lazy’] Def
Expand Down Expand Up @@ -263,7 +263,7 @@ Pattern ::= Pattern1 { ‘|’ Pattern1 }
Pattern1 ::= Pattern2 [‘:’ RefinedType] Bind(name, Typed(Ident(wildcard), tpe))
| ‘given’ PatVar ‘:’ RefinedType
Pattern2 ::= [id ‘@’] InfixPattern Bind(name, pat)
InfixPattern ::= SimplePattern { id [cnl] SimplePattern } InfixOp(pat, op, pat)
InfixPattern ::= SimplePattern { id [nl] SimplePattern } InfixOp(pat, op, pat)
SimplePattern ::= PatVar Ident(wildcard)
| Literal Bind(name, Ident(wildcard))
| ‘(’ [Patterns] ‘)’ Parens(pats) Tuple(pats)
Expand Down Expand Up @@ -400,7 +400,7 @@ ConstrExpr ::= SelfInvocation
| ‘{’ SelfInvocation {semi BlockStat} ‘}’
SelfInvocation ::= ‘this’ ArgumentExprs {ArgumentExprs}

TemplateBody ::= [cnl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’ (self, stats)
TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’ (self, stats)
TemplateStat ::= Import
| Export
| {Annotation [nl]} {Modifier} Def
Expand All @@ -410,7 +410,7 @@ TemplateStat ::= Import
SelfType ::= id [‘:’ InfixType] ‘=>’ ValDef(_, name, tpt, _)
| ‘this’ ‘:’ InfixType ‘=>’

EnumBody ::= [cnl] ‘{’ [SelfType] EnumStat {semi EnumStat} ‘}’
EnumBody ::= [nl] ‘{’ [SelfType] EnumStat {semi EnumStat} ‘}’
EnumStat ::= TemplateStat
| {Annotation [nl]} {Modifier} EnumCase
EnumCase ::= ‘case’ (id ClassConstr [‘extends’ ConstrApps]] | ids)
Expand All @@ -422,7 +422,7 @@ TopStat ::= Import
| Packaging
| PackageObject
|
Packaging ::= ‘package’ QualId [cnl] ‘{’ TopStatSeq ‘}’ Package(qid, stats)
Packaging ::= ‘package’ QualId [nl] ‘{’ TopStatSeq ‘}’ Package(qid, stats)
PackageObject ::= ‘package’ ‘object’ ObjectDef object with package in mods.

CompilationUnit ::= {‘package’ QualId (semi | cnl)} TopStatSeq Package(qid, stats)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/reference/other-new-features/indentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ There are two rules:
class, object, given, or enum definition, in an enum case, or after a package clause, or
- after one of the following tokens:
```
= => <- if then else while do try catch finally for yield match
= => <- if then else while do try catch finally for yield match return
```
If an `<indent>` is inserted, the indentation width of the token on the next line
is pushed onto `IW`, which makes it the new current indentation width.
Expand Down