alexeyxo / protobuf-swift

Google ProtocolBuffers for Apple Swift
http://protobuf.io/#swift
Apache License 2.0
938 stars 138 forks source link

Reserved Keyword Escaping #172

Closed pmaene closed 8 years ago

pmaene commented 8 years ago

Version of protoc (protoc --version)

3.0 [ProtoBuf3.0-Swift3.0]

Version of ProtocolBuffers.framework

3.0 [ProtoBuf3.0-Swift3.0]

.proto file to reproduce

syntax = "proto3";

import "google/protobuf/swift-descriptor.proto";
option (.google.protobuf.swift_file_options).class_prefix = "Native";

enum Type {
    INIT = 0;
}

Description

First of all, thanks a lot for keeping up with all the changes in each new Xcode beta release! When compiling this ProtoBuf 3.0 specification for Swift, two errors related to reserved keyword escaping pop up:

  1. The prefixed return type of functions which return have an instance of Type as their result, will be incorrectly escaped as NativeType, instead of NativeType.
  2. On the other hand, the INIT element of the enum will not be escaped. It is mapped to .ini, and not .ìnit`.
DouglasHeriot commented 8 years ago

I just ran into a similar issue – I think my pull request #173 fixes your second init case. Since I’m in the area, I also had a go at fixing your first case too (haven’t tested it though). Issue seems to be it was going through the SafeName filter before concatenating your prefix on.

pmaene commented 8 years ago

Thanks for the quick replies @DouglasHeriot and @alexeyxo! Even when correctly escaped, the second case does not work. It seems there's a compiler bug that prevents an "init" enum element from working correctly (https://bugs.swift.org/browse/SR-1660).