@@ -550,18 +550,23 @@ object Parsers {
550550 }
551551
552552 /** Accept identifier and return Ident with its name as a term name. */
553- def termIdent (): Ident = atSpan(in.offset) {
554- makeIdent(in.token, ident())
555- }
553+ def termIdent (): Ident =
554+ makeIdent(in.token, in.offset, ident())
556555
557556 /** Accept identifier and return Ident with its name as a type name. */
558- def typeIdent (): Ident = atSpan(in.offset) {
559- makeIdent(in.token, ident().toTypeName)
560- }
557+ def typeIdent (): Ident =
558+ makeIdent(in.token, in.offset, ident().toTypeName)
561559
562- private def makeIdent (tok : Token , name : Name ) =
563- if (tok == BACKQUOTED_IDENT ) BackquotedIdent (name)
564- else Ident (name)
560+ private def makeIdent (tok : Token , offset : Offset , name : Name ) = {
561+ val tree =
562+ if (tok == BACKQUOTED_IDENT ) BackquotedIdent (name)
563+ else Ident (name)
564+
565+ // Make sure that even trees with parsing errors have a offset that is within the offset
566+ val errorOffset = offset min (in.lastOffset - 1 )
567+ if (tree.name == nme.ERROR && tree.span == NoSpan ) tree.withSpan(Span (errorOffset, errorOffset))
568+ else atSpan(offset)(tree)
569+ }
565570
566571 def wildcardIdent (): Ident =
567572 atSpan(accept(USCORE )) { Ident (nme.WILDCARD ) }
0 commit comments