File tree Expand file tree Collapse file tree 2 files changed +18
-13
lines changed
compiler/src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 2 files changed +18
-13
lines changed Original file line number Diff line number Diff line change @@ -3844,19 +3844,21 @@ object Parsers {
38443844 */
38453845 def refineStatSeq (): List [Tree ] = {
38463846 val stats = new ListBuffer [Tree ]
3847- def checkLegal (tree : Tree ): List [Tree ] = {
3848- val isLegal = tree match {
3849- case tree : ValDef => tree.rhs.isEmpty && ! tree.mods.flags.is(Mutable )
3850- case tree : DefDef => tree.rhs.isEmpty
3851- case tree : TypeDef => true
3852- case _ => false
3853- }
3854- if (isLegal) tree :: Nil
3855- else {
3856- syntaxError(" illegal refinement" , tree.span)
3857- Nil
3858- }
3859- }
3847+ def checkLegal (tree : Tree ): List [Tree ] =
3848+ val problem = tree match
3849+ case tree : MemberDef if ! (tree.mods.flags & ModifierFlags ).isEmpty =>
3850+ i " refinement cannot be ${(tree.mods.flags & ModifierFlags ).flagsString}"
3851+ case tree : ValOrDefDef =>
3852+ if tree.rhs.isEmpty then " "
3853+ else " refinement in cannot have a right-hand side"
3854+ case tree : TypeDef =>
3855+ if ! tree.isClassDef then " "
3856+ else " refinement cannot be a class or trait"
3857+ case _ =>
3858+ " this kind of definition cannot be a refinement"
3859+ if problem.isEmpty then tree :: Nil
3860+ else { syntaxError(problem, tree.span); Nil }
3861+
38603862 while (! isStatSeqEnd) {
38613863 if (isDclIntro)
38623864 stats ++= checkLegal(defOrDcl(in.offset, Modifiers ()))
Original file line number Diff line number Diff line change 1+ trait A
2+ trait B
3+ type T = {given (given a : A ) as B }
You can’t perform that action at this time.
0 commit comments