Skip to content
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

Trailing commas in class and function headers crash scalariform #284

Open
fdietze opened this issue Jun 14, 2019 · 3 comments
Open

Trailing commas in class and function headers crash scalariform #284

fdietze opened this issue Jun 14, 2019 · 3 comments

Comments

@fdietze
Copy link

fdietze commented Jun 14, 2019

While this works:

$ scalariform
class A(x:Int,
y:int
)

class A(
  x: Int,
  y: int
)

Adding a trailing comma crashes scalariform 2.10:

$ scalariform
class A(x:Int,
y:Int,
)

Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: Parse tokens differ from expected.
  Actual = 
Token(CLASS,class,0,class)
Token(VARID,A,6,A)
Token(LPAREN,(,7,()
Token(VARID,x,8,x)
Token(COLON,:,9,:)
Token(VARID,Int,10,Int)
Token(COMMA,,,13,,)
Token(VARID,y,15,y)
Token(COLON,:,16,:)
Token(VARID,Int,17,Int)
Token(RPAREN,),22,))
Token(NEWLINES,

,23,

)
  expected = 
Token(CLASS,class,0,class)
Token(VARID,A,6,A)
Token(LPAREN,(,7,()
Token(VARID,x,8,x)
Token(COLON,:,9,:)
Token(VARID,Int,10,Int)
Token(COMMA,,,13,,)
Token(VARID,y,15,y)
Token(COLON,:,16,:)
Token(VARID,Int,17,Int)
Token(COMMA,,,20,,)
Token(RPAREN,),22,))
Token(NEWLINES,

,23,

)
  parseResult = 
CompilationUnit(StatSeq(None,Some(FullDefOrDcl(List(),List(),TmplDef(List(Token(CLASS,class,0,class)),Token(VARID,A,6,A),None,List(),None,Some(ParamClauses(None,List((ParamClause(Token(LPAREN,(,7,(),None,Some(Param(List(),List(),None,Token(VARID,x,8,x),Some((Token(COLON,:,9,:),Type(List(Type(List(GeneralTokens(List(Token(VARID,Int,10,Int))))))))),None)),List((Token(COMMA,,,13,,),Param(List(),List(),None,Token(VARID,y,15,y),Some((Token(COLON,:,16,:),Type(List(Type(List(GeneralTokens(List(Token(VARID,Int,17,Int))))))))),None))),Token(RPAREN,),22,)),Some(Token(COMMA,,,20,,))),None)))),None,None))),List((Token(NEWLINES,

,23,

),None))),Token(EOF,,25,))
	at scala.Predef$.require(Predef.scala:281)
	at scalariform.formatter.SpecificFormatter.fullFormat(SpecificFormatter.scala:54)
	at scalariform.formatter.SpecificFormatter.fullFormat$(SpecificFormatter.scala:27)
	at scalariform.formatter.ScalaFormatter$$anon$1.fullFormat(ScalaFormatter.scala:593)
	at scalariform.formatter.ScalaFormatter$.formatAsEdits(ScalaFormatter.scala:602)
	at scalariform.formatter.ScalaFormatter$.format(ScalaFormatter.scala:586)
	at scalariform.commandline.Main$.$anonfun$process$19(Main.scala:167)
	at scalariform.commandline.Main$.transformSysInToSysOut(Main.scala:209)
	at scalariform.commandline.Main$.process(Main.scala:179)
	at scalariform.commandline.Main$.main(Main.scala:16)
	at scalariform.commandline.Main.main(Main.scala)

The same happens with trailing commas in functions:

$ scalariform
def f(x:Int,
y:Int,
) = x + y

Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: Parse tokens differ from expected.
  Actual = 
Token(DEF,def,0,def)
Token(VARID,f,4,f)
Token(LPAREN,(,5,()
Token(VARID,x,6,x)
Token(COLON,:,7,:)
Token(VARID,Int,8,Int)
Token(COMMA,,,11,,)
Token(VARID,y,13,y)
Token(COLON,:,14,:)
Token(VARID,Int,15,Int)
Token(RPAREN,),20,))
Token(EQUALS,=,22,=)
Token(VARID,x,24,x)
Token(PLUS,+,26,+)
Token(VARID,y,28,y)
Token(NEWLINE,
,29,
)
  expected = 
Token(DEF,def,0,def)
Token(VARID,f,4,f)
Token(LPAREN,(,5,()
Token(VARID,x,6,x)
Token(COLON,:,7,:)
Token(VARID,Int,8,Int)
Token(COMMA,,,11,,)
Token(VARID,y,13,y)
Token(COLON,:,14,:)
Token(VARID,Int,15,Int)
Token(COMMA,,,18,,)
Token(RPAREN,),20,))
Token(EQUALS,=,22,=)
Token(VARID,x,24,x)
Token(PLUS,+,26,+)
Token(VARID,y,28,y)
Token(NEWLINE,
,29,
)
  parseResult = 
CompilationUnit(StatSeq(None,Some(FullDefOrDcl(List(),List(),FunDefOrDcl(Token(DEF,def,0,def),Token(VARID,f,4,f),None,ParamClauses(None,List((ParamClause(Token(LPAREN,(,5,(),None,Some(Param(List(),List(),None,Token(VARID,x,6,x),Some((Token(COLON,:,7,:),Type(List(Type(List(GeneralTokens(List(Token(VARID,Int,8,Int))))))))),None)),List((Token(COMMA,,,11,,),Param(List(),List(),None,Token(VARID,y,13,y),Some((Token(COLON,:,14,:),Type(List(Type(List(GeneralTokens(List(Token(VARID,Int,15,Int))))))))),None))),Token(RPAREN,),20,)),Some(Token(COMMA,,,18,,))),None))),None,Some(ExprFunBody(Token(EQUALS,=,22,=),None,Expr(List(InfixExpr(List(CallExpr(None,Token(VARID,x,24,x),None,List(),None)),Token(PLUS,+,26,+),None,List(CallExpr(None,Token(VARID,y,28,y),None,List(),None))))))),false))),List((Token(NEWLINE,
,29,
),None))),Token(EOF,,30,))
	at scala.Predef$.require(Predef.scala:281)
	at scalariform.formatter.SpecificFormatter.fullFormat(SpecificFormatter.scala:54)
	at scalariform.formatter.SpecificFormatter.fullFormat$(SpecificFormatter.scala:27)
	at scalariform.formatter.ScalaFormatter$$anon$1.fullFormat(ScalaFormatter.scala:593)
	at scalariform.formatter.ScalaFormatter$.formatAsEdits(ScalaFormatter.scala:602)
	at scalariform.formatter.ScalaFormatter$.format(ScalaFormatter.scala:586)
	at scalariform.commandline.Main$.$anonfun$process$19(Main.scala:167)
	at scalariform.commandline.Main$.transformSysInToSysOut(Main.scala:209)
	at scalariform.commandline.Main$.process(Main.scala:179)
	at scalariform.commandline.Main$.main(Main.scala:16)
	at scalariform.commandline.Main.main(Main.scala)
@udalrich
Copy link

udalrich commented Sep 3, 2019

This also crashes scalariform in import statements:

package test

import scala.collection.{
    Map,
    Seq,
}

Compiling with sbt yields

[warn] Scalariform parser error for /projects//src/main/scala/com/example/Test.scala: Expected identifier, but got Token(RBRACE,},58,})

@igorgatis
Copy link

Any news on this?

@hubertta
Copy link

I made a pull request that should take care of this problem: #296

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants