Skip to content

Commit

Permalink
[codegen] add scala 3 keywords to collision avoidance (#1392)
Browse files Browse the repository at this point in the history
* [codegen] add scala 3 keywords to collision avoidance

* testfix

* fmt

* Add changelog entry

* remove scala 3 soft keywords

* add scala3 reserved keywords to sample specs

* remove redundant unit test

---------

Co-authored-by: David Francoeur <dfrancoeur04@gmail.com>
  • Loading branch information
jpassaro and daddykotex committed Feb 6, 2024
1 parent 575136f commit cddd682
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.18.8

* Fix collision avoidance algorithm to cover Scala 3 keywords

# 0.18.7

* Added support for `@httpResponseCode` on newtypes (integer shapes that aren't exactly `smithy.api#Integer`), as well as refinements (e.g. ints with a `@range` constraint).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package smithy4s.example.collision

import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.struct

final case class Scala3ReservedKeywords(_export: Option[String] = None, _enum: Option[String] = None)

object Scala3ReservedKeywords extends ShapeTag.Companion[Scala3ReservedKeywords] {
val id: ShapeId = ShapeId("smithy4s.example.collision", "Scala3ReservedKeywords")

val hints: Hints = Hints.empty

implicit val schema: Schema[Scala3ReservedKeywords] = struct(
String.schema.optional[Scala3ReservedKeywords]("export", _._export),
String.schema.optional[Scala3ReservedKeywords]("enum", _._enum),
){
Scala3ReservedKeywords.apply
}.withId(id).addHints(hints)
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,14 @@ private[internals] object CollisionAvoidance {
"notify",
"notifyAll",
"toString",
"wait"
"wait",

// scala 3 "regular" keywords
// https://docs.scala-lang.org/scala3/guides/migration/incompat-syntactic.html#restricted-keywords
"enum",
"export",
"given",
"then"
)

class Names() {
Expand Down
5 changes: 5 additions & 0 deletions sampleSpecs/reservednames.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,8 @@ enum KeywordEnum {
implicit
package = "class"
}

structure Scala3ReservedKeywords {
export: String
enum: String
}

0 comments on commit cddd682

Please sign in to comment.