Skip to content

Commit

Permalink
make generated case classes final by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
stewSquared committed Dec 9, 2016
1 parent bd3c24b commit 0e869e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Expand Up @@ -117,8 +117,10 @@ abstract class AbstractGenerator[Code,TermName,TypeName](model: m.Model)
trait EntityTypeDef extends TypeDef{ trait EntityTypeDef extends TypeDef{
/** Column types */ /** Column types */
def types: Code = compoundType(columns.map(_.exposedType)) def types: Code = compoundType(columns.map(_.exposedType))
/** Indicated whether a case class should be generated. Otherwise a type alias. */ /** Indicates whether a case class should be generated. Otherwise a type alias. */
def classEnabled = mappingEnabled def classEnabled = mappingEnabled
/** Indicates whether a generated case class should be final. */
def caseClassFinal = true
def doc = def doc =
if(classEnabled){ if(classEnabled){
s"Entity class storing rows of table ${TableValue.name}\n" + s"Entity class storing rows of table ${TableValue.name}\n" +
Expand Down
Expand Up @@ -78,6 +78,7 @@ abstract class AbstractSourceCodeGenerator(model: m.Model)
).mkString(", ") ).mkString(", ")
if(classEnabled){ if(classEnabled){
val prns = (parents.take(1).map(" extends "+_) ++ parents.drop(1).map(" with "+_)).mkString("") val prns = (parents.take(1).map(" extends "+_) ++ parents.drop(1).map(" with "+_)).mkString("")
(if(caseClassFinal) "final " else "") +
s"""case class $name($args)$prns""" s"""case class $name($args)$prns"""
} else { } else {
s""" s"""
Expand Down

3 comments on commit 0e869e9

@dmarwick
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just upgraded to 3.2.0 and this change produces a compiler warning:

The outer reference in this type test cannot be checked at run time.

Is this expected by default? Thanks

@stewSquared
Copy link
Contributor Author

@stewSquared stewSquared commented on 0e869e9 Apr 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmarwick Setting default to true was a mistake because of the errors in the default code generator. It's set to false in 3.2.1. See #1709

For now, you'll have to either (1) not generate case classes inside the table trait or (2) override caseClassFinal to default to false.

@dmarwick
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @stewSquared! We overrode it to false for now and will plan to revert the override in 3.2.1+.

Please sign in to comment.