mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Introduce isDecl and getDeclType
fix enum logic issue fix tests guard against null types
This commit is contained in:
@@ -78,7 +78,7 @@ deriveRawValueInit(AbstractFunctionDecl *initDecl, void *) {
|
||||
auto *rawValueDecl = new (C) ParamDecl(
|
||||
SourceLoc(), SourceLoc(), C.Id_rawValue,
|
||||
SourceLoc(), C.Id_rawValue, parentDC);
|
||||
rawValueDecl->setInterfaceType(C.getIntDecl()->getDeclaredInterfaceType());
|
||||
rawValueDecl->setInterfaceType(C.getIntType());
|
||||
rawValueDecl->setSpecifier(ParamSpecifier::Default);
|
||||
rawValueDecl->setImplicit();
|
||||
auto *paramList = ParameterList::createWithoutLoc(rawValueDecl);
|
||||
@@ -332,10 +332,9 @@ static bool canSynthesizeCodingKey(DerivedConformance &derived) {
|
||||
auto *parentDC = derived.getConformanceContext();
|
||||
rawType = parentDC->mapTypeIntoContext(rawType);
|
||||
|
||||
auto &C = derived.Context;
|
||||
auto *nominal = rawType->getCanonicalType()->getAnyNominal();
|
||||
if (nominal != C.getStringDecl() && nominal != C.getIntDecl())
|
||||
if (!rawType->isString() && !rawType->isInt()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto inherited = enumDecl->getInherited();
|
||||
@@ -363,9 +362,9 @@ ValueDecl *DerivedConformance::deriveCodingKey(ValueDecl *requirement) {
|
||||
auto name = requirement->getBaseName();
|
||||
if (name == Context.Id_stringValue) {
|
||||
// Synthesize `var stringValue: String { get }`
|
||||
auto stringType = Context.getStringDecl()->getDeclaredInterfaceType();
|
||||
auto synth = [rawType, stringType](AbstractFunctionDecl *getterDecl) {
|
||||
if (rawType && rawType->isEqual(stringType)) {
|
||||
auto stringType = Context.getStringType();
|
||||
auto synth = [rawType](AbstractFunctionDecl *getterDecl) {
|
||||
if (rawType && rawType->isString()) {
|
||||
// enum SomeStringEnum : String {
|
||||
// case A, B, C
|
||||
// @derived var stringValue: String {
|
||||
@@ -394,11 +393,11 @@ ValueDecl *DerivedConformance::deriveCodingKey(ValueDecl *requirement) {
|
||||
|
||||
} else if (name == Context.Id_intValue) {
|
||||
// Synthesize `var intValue: Int? { get }`
|
||||
auto intType = Context.getIntDecl()->getDeclaredInterfaceType();
|
||||
auto intType = Context.getIntType();
|
||||
auto optionalIntType = OptionalType::get(intType);
|
||||
|
||||
auto synth = [rawType, intType](AbstractFunctionDecl *getterDecl) {
|
||||
if (rawType && rawType->isEqual(intType)) {
|
||||
auto synth = [rawType](AbstractFunctionDecl *getterDecl) {
|
||||
if (rawType && rawType->isInt()) {
|
||||
// enum SomeIntEnum : Int {
|
||||
// case A = 1, B = 2, C = 3
|
||||
// @derived var intValue: Int? {
|
||||
@@ -423,9 +422,9 @@ ValueDecl *DerivedConformance::deriveCodingKey(ValueDecl *requirement) {
|
||||
if (argumentNames.size() == 1) {
|
||||
if (argumentNames[0] == Context.Id_stringValue) {
|
||||
// Derive `init?(stringValue:)`
|
||||
auto stringType = Context.getStringDecl()->getDeclaredInterfaceType();
|
||||
auto synth = [rawType, stringType](AbstractFunctionDecl *initDecl) {
|
||||
if (rawType && rawType->isEqual(stringType)) {
|
||||
auto stringType = Context.getStringType();
|
||||
auto synth = [rawType](AbstractFunctionDecl *initDecl) {
|
||||
if (rawType && rawType->isString()) {
|
||||
// enum SomeStringEnum : String {
|
||||
// case A = "a", B = "b", C = "c"
|
||||
// @derived init?(stringValue: String) {
|
||||
@@ -456,9 +455,9 @@ ValueDecl *DerivedConformance::deriveCodingKey(ValueDecl *requirement) {
|
||||
return deriveInitDecl(*this, stringType, Context.Id_stringValue, synth);
|
||||
} else if (argumentNames[0] == Context.Id_intValue) {
|
||||
// Synthesize `init?(intValue:)`
|
||||
auto intType = Context.getIntDecl()->getDeclaredInterfaceType();
|
||||
auto synthesizer = [rawType, intType](AbstractFunctionDecl *initDecl) {
|
||||
if (rawType && rawType->isEqual(intType)) {
|
||||
auto intType = Context.getIntType();
|
||||
auto synthesizer = [rawType](AbstractFunctionDecl *initDecl) {
|
||||
if (rawType && rawType->isInt()) {
|
||||
// enum SomeIntEnum : Int {
|
||||
// case A = 1, B = 2, C = 3
|
||||
// @derived init?(intValue: Int) {
|
||||
|
||||
Reference in New Issue
Block a user