Skip to content

Commit 719af9a

Browse files
committed
Added type annotations for precondition in TokenKind
1 parent 676e668 commit 719af9a

File tree

2 files changed

+37
-74
lines changed

2 files changed

+37
-74
lines changed

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/TokenKindFile.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ let tokenKindFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
238238
}
239239
} else if tokenSpec.text != nil {
240240
SwitchCaseSyntax("case .\(tokenSpec.varOrCaseName):") {
241-
try! VariableDeclSyntax("let isNotDefaultText: Bool = rawKind.defaultTextString == text")
242-
ExprSyntax("precondition(text.isEmpty || isNotDefaultText)")
241+
ExprSyntax("precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)")
243242
StmtSyntax("return .\(tokenSpec.varOrCaseName)")
244243
}
245244
} else {

Sources/SwiftSyntax/generated/TokenKind.swift

Lines changed: 36 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -739,56 +739,45 @@ extension TokenKind {
739739
public static func fromRaw(kind rawKind: RawTokenKind, text: String) -> TokenKind {
740740
switch rawKind {
741741
case .arrow:
742-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
743-
precondition(text.isEmpty || isNotDefaultText)
742+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
744743
return .arrow
745744
case .atSign:
746-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
747-
precondition(text.isEmpty || isNotDefaultText)
745+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
748746
return .atSign
749747
case .backslash:
750-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
751-
precondition(text.isEmpty || isNotDefaultText)
748+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
752749
return .backslash
753750
case .backtick:
754-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
755-
precondition(text.isEmpty || isNotDefaultText)
751+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
756752
return .backtick
757753
case .binaryOperator:
758754
return .binaryOperator(text)
759755
case .colon:
760-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
761-
precondition(text.isEmpty || isNotDefaultText)
756+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
762757
return .colon
763758
case .comma:
764-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
765-
precondition(text.isEmpty || isNotDefaultText)
759+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
766760
return .comma
767761
case .dollarIdentifier:
768762
return .dollarIdentifier(text)
769763
case .ellipsis:
770-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
771-
precondition(text.isEmpty || isNotDefaultText)
764+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
772765
return .ellipsis
773766
case .endOfFile:
774-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
775-
precondition(text.isEmpty || isNotDefaultText)
767+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
776768
return .endOfFile
777769
case .equal:
778-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
779-
precondition(text.isEmpty || isNotDefaultText)
770+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
780771
return .equal
781772
case .exclamationMark:
782-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
783-
precondition(text.isEmpty || isNotDefaultText)
773+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
784774
return .exclamationMark
785775
case .floatLiteral:
786776
return .floatLiteral(text)
787777
case .identifier:
788778
return .identifier(text)
789779
case .infixQuestionMark:
790-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
791-
precondition(text.isEmpty || isNotDefaultText)
780+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
792781
return .infixQuestionMark
793782
case .integerLiteral:
794783
return .integerLiteral(text)
@@ -798,70 +787,54 @@ extension TokenKind {
798787
return .keyword(Keyword(text)!)
799788
}
800789
case .leftAngle:
801-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
802-
precondition(text.isEmpty || isNotDefaultText)
790+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
803791
return .leftAngle
804792
case .leftBrace:
805-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
806-
precondition(text.isEmpty || isNotDefaultText)
793+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
807794
return .leftBrace
808795
case .leftParen:
809-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
810-
precondition(text.isEmpty || isNotDefaultText)
796+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
811797
return .leftParen
812798
case .leftSquare:
813-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
814-
precondition(text.isEmpty || isNotDefaultText)
799+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
815800
return .leftSquare
816801
case .multilineStringQuote:
817-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
818-
precondition(text.isEmpty || isNotDefaultText)
802+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
819803
return .multilineStringQuote
820804
case .period:
821-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
822-
precondition(text.isEmpty || isNotDefaultText)
805+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
823806
return .period
824807
case .postfixOperator:
825808
return .postfixOperator(text)
826809
case .postfixQuestionMark:
827-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
828-
precondition(text.isEmpty || isNotDefaultText)
810+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
829811
return .postfixQuestionMark
830812
case .pound:
831-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
832-
precondition(text.isEmpty || isNotDefaultText)
813+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
833814
return .pound
834815
case .poundAvailable:
835-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
836-
precondition(text.isEmpty || isNotDefaultText)
816+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
837817
return .poundAvailable
838818
case .poundElse:
839-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
840-
precondition(text.isEmpty || isNotDefaultText)
819+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
841820
return .poundElse
842821
case .poundElseif:
843-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
844-
precondition(text.isEmpty || isNotDefaultText)
822+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
845823
return .poundElseif
846824
case .poundEndif:
847-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
848-
precondition(text.isEmpty || isNotDefaultText)
825+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
849826
return .poundEndif
850827
case .poundIf:
851-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
852-
precondition(text.isEmpty || isNotDefaultText)
828+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
853829
return .poundIf
854830
case .poundSourceLocation:
855-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
856-
precondition(text.isEmpty || isNotDefaultText)
831+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
857832
return .poundSourceLocation
858833
case .poundUnavailable:
859-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
860-
precondition(text.isEmpty || isNotDefaultText)
834+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
861835
return .poundUnavailable
862836
case .prefixAmpersand:
863-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
864-
precondition(text.isEmpty || isNotDefaultText)
837+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
865838
return .prefixAmpersand
866839
case .prefixOperator:
867840
return .prefixOperator(text)
@@ -872,46 +845,37 @@ extension TokenKind {
872845
case .regexPoundDelimiter:
873846
return .regexPoundDelimiter(text)
874847
case .regexSlash:
875-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
876-
precondition(text.isEmpty || isNotDefaultText)
848+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
877849
return .regexSlash
878850
case .rightAngle:
879-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
880-
precondition(text.isEmpty || isNotDefaultText)
851+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
881852
return .rightAngle
882853
case .rightBrace:
883-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
884-
precondition(text.isEmpty || isNotDefaultText)
854+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
885855
return .rightBrace
886856
case .rightParen:
887-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
888-
precondition(text.isEmpty || isNotDefaultText)
857+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
889858
return .rightParen
890859
case .rightSquare:
891-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
892-
precondition(text.isEmpty || isNotDefaultText)
860+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
893861
return .rightSquare
894862
case .semicolon:
895-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
896-
precondition(text.isEmpty || isNotDefaultText)
863+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
897864
return .semicolon
898865
case .shebang:
899866
return .shebang(text)
900867
case .singleQuote:
901-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
902-
precondition(text.isEmpty || isNotDefaultText)
868+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
903869
return .singleQuote
904870
case .stringQuote:
905-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
906-
precondition(text.isEmpty || isNotDefaultText)
871+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
907872
return .stringQuote
908873
case .stringSegment:
909874
return .stringSegment(text)
910875
case .unknown:
911876
return .unknown(text)
912877
case .wildcard:
913-
let isNotDefaultText: Bool = rawKind.defaultTextString == text
914-
precondition(text.isEmpty || isNotDefaultText)
878+
precondition(((text.isEmpty as Bool) || ((rawKind.defaultTextString == text) as Bool)) as Bool)
915879
return .wildcard
916880
}
917881
}

0 commit comments

Comments
 (0)