mrousavy / nitro

🔥 Insanely fast native C++, Swift or Kotlin modules with a statically compiled binding layer to JSI
https://nitro.margelo.com
MIT License
598 stars 15 forks source link

Using `protocol` as a property name in spec will result in an error #124

Closed grabbou closed 1 month ago

grabbou commented 1 month ago

For the spec:

export interface Foo {
  protocol: string
}

The following generated code:

 init(protocol: String) {
    self.init(std.string(protocol))
  }

  var protocol: String {
    @inline(__always)
    get {
      return String(self.__protocol)
    }
    @inline(__always)
    set {
      self.__protocol = std.string(newValue)
    }
  }
}

is not correct, obviously haha. I will fix that myself, but perhaps Nitro could throw an error.

mrousavy commented 1 month ago

hmm this is a bit tricky since we technically need to escape all keywords of Swift and C++.

Not sure if that's something codegen should do, as that just adds a lot of extra complexity

grabbou commented 1 month ago

Yeah, I agree. My suggestion was that codegen could throw an error that this property name is not allowed, like it does for other issues already.