Skip to content

Move out enum tests into a separate CXXInterop/enum directory #30182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions test/CXXInterop/enum/Inputs/enum-anon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
enum {
Constant1,
Constant2
};

enum {
VarConstant1,
VarConstant2
} global;

typedef struct SR2511 {
int x;

enum {
SR2511A = 0, SR2511B, SR2511C
} y;

int z;
} SR2511;
8 changes: 8 additions & 0 deletions test/CXXInterop/enum/Inputs/module.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module EnumAnon {
header "enum-anon.h"
}

module EnumExhaustivity {
header "EnumExhaustivity.h"
export *
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// RUN: %target-swift-frontend -emit-ir %s -enable-objc-interop -import-objc-header %S/Inputs/enum-anon.h | %FileCheck -check-prefix=CHECK -check-prefix=CHECK-%target-runtime %s
// RUN: %target-swift-frontend -emit-ir %s -I %S/Inputs | %FileCheck -check-prefix=CHECK %s
// RUN: %target-swift-frontend -emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck -check-prefix=CHECK %s

import EnumAnon

func verifyIsInt(_: inout Int) { }
func verifyIsInt32(_: inout Int32) { }
Expand All @@ -23,11 +26,6 @@ public func testIR(x: UnsafePointer<SR2511>) -> CInt {
// CHECK: store i32 1, i32* getelementptr inbounds ([[ENUM_TYPE]], [[ENUM_TYPE]]* bitcast (i32* @global to [[ENUM_TYPE]]*), i32 0, i32 0), align 4
global = VarConstant2

#if _runtime(_ObjC)
// CHECK-objc: store i16 1, i16* getelementptr inbounds (%Ts6UInt16V, %Ts6UInt16V* bitcast (i16* @usGlobal to %Ts6UInt16V*), i32 0, i32 0), align 2
usGlobal = USVarConstant2
#endif

// Force the definition of the type above.
// CHECK: ret
return x.pointee.z
Expand Down
17 changes: 17 additions & 0 deletions test/CXXInterop/enum/enum-anon.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs -DDIAGS -verify
// RUN: %target-swift-frontend -typecheck %s -enable-cxx-interop -I %S/Inputs -DDIAGS -verify
import EnumAnon

func testDiags() {

let us2: UInt16 = 0
let _: String = us2 // expected-error {{cannot convert value of type 'UInt16' to specified type 'String'}}

let usVar2: UInt16 = 0
let _: String = usVar2 // expected-error {{cannot convert value of type 'UInt16' to specified type 'String'}}

// The nested anonymous enum value should still have top-level scope, because
// that's how C works. It should also have the same type as the field (above).
let _: String = SR2511.SR2511B // expected-error {{type 'SR2511' has no member 'SR2511B'}}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -emit-ir -primary-file %s -I %S/Inputs/custom-modules -module-cache-path %t -enable-cxx-interop -o - | %FileCheck %s
// RUN: %target-swift-frontend -emit-ir -primary-file %s -I %S/../../ClangImporter/Inputs/ -module-cache-path %t -enable-cxx-interop -o - | %FileCheck %s

import CXXInterop

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -typecheck %s -Xcc -isystem -Xcc %S/Inputs/custom-modules -verify -enable-nonfrozen-enum-exhaustivity-diagnostics
// RUN: %target-swift-frontend -typecheck %s -Xcc -isystem -Xcc %S/Inputs -verify -enable-nonfrozen-enum-exhaustivity-diagnostics

import EnumExhaustivity

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs/custom-modules -verify -warnings-as-errors -enable-nonfrozen-enum-exhaustivity-diagnostics
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs -verify -warnings-as-errors -enable-nonfrozen-enum-exhaustivity-diagnostics

// RUN: %target-swift-ide-test -source-filename %s -print-module -module-to-print EnumExhaustivity -I %S/Inputs/custom-modules | %FileCheck %s
// RUN: %target-swift-ide-test -source-filename %s -print-module -module-to-print EnumExhaustivity -I %S/Inputs | %FileCheck %s

// CHECK-LABEL: {{^}}enum RegularEnum : {{.+}} {
// CHECK: case A
Expand Down
5 changes: 0 additions & 5 deletions test/ClangImporter/Inputs/custom-modules/module.map
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ module ctypes_bits_exported {
export *
}

module EnumExhaustivity {
header "EnumExhaustivity.h"
export *
}

module ExternIntX { header "x.h" }

module HasSubmodule {
Expand Down
22 changes: 0 additions & 22 deletions test/ClangImporter/Inputs/enum-anon.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
enum {
Constant1,
Constant2
};

enum {
VarConstant1,
VarConstant2
} global;

typedef struct SR2511 {
int x;

enum {
SR2511A = 0, SR2511B, SR2511C
} y;

int z;
} SR2511;

#if __OBJC__
enum : unsigned short {
USConstant1,
USConstant2
Expand All @@ -28,4 +7,3 @@ enum : unsigned short {
USVarConstant1,
USVarConstant2
} usGlobal;
#endif // __OBJC__
16 changes: 2 additions & 14 deletions test/ClangImporter/enum-anon.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
// RUN: %target-swift-frontend -typecheck %s -enable-objc-interop -import-objc-header %S/Inputs/enum-anon.h -DDIAGS -verify

// REQUIRES: objc_interop

func testDiags() {
#if _runtime(_ObjC)
let us2 = USConstant2
#else
let us2: UInt16 = 0
#endif
let _: String = us2 // expected-error {{cannot convert value of type 'UInt16' to specified type 'String'}}

#if _runtime(_ObjC)
let usVar2 = USVarConstant2
#else
let usVar2: UInt16 = 0
#endif
let _: String = usVar2 // expected-error {{cannot convert value of type 'UInt16' to specified type 'String'}}

// The nested anonymous enum value should still have top-level scope, because
// that's how C works. It should also have the same type as the field (above).
let _: String = SR2511.SR2511B // expected-error {{type 'SR2511' has no member 'SR2511B'}}
}