swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.33k stars 10.34k forks source link

[SR-15182] New warning when using `self` as enum case #57505

Open adam-fowler opened 3 years ago

adam-fowler commented 3 years ago
Previous ID SR-15182
Radar rdar://problem/83164358
Original Reporter @adam-fowler
Type Bug
Environment Using macOS snapshot from 10/09/2021
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 42331d2e2ceb58866cd3a90c479a0c17

is duplicated by:

Issue Description:

The following code used to work without complaint

enum Test: String {
    case `self`
}
let test = Test.`self`

I am now getting on the line `let test = ... ` the following warning

<unknown>:0: warning: 'self' refers to the method 'Test.self', which may be unexpected
<unknown>:0: note: use 'Test.self' to silence this warning

Is this to be expected from now on

typesanitizer commented 3 years ago

cc jackmarch (JIRA User)

@swift-ci create

swift-ci commented 3 years ago

Comment by Jack March (JIRA)

thanks theindigamer (JIRA User), will aim to fix this by the end of the week (hopefully tonight)

swift-ci commented 3 years ago

Comment by Jack March (JIRA)

@adam-fowler I couldn't reproduce with your example, though on further experimentation I reproduced with the following code:

enum EnumWithSelfCase {
    case `self`

    var computedProperty: EnumWithSelfCase {
        .self // error appears here incorrectly
    }
}

Could you please provide some more info about where the error message appears, presumably somewhere you reference the case .self on enum Test so I can make sure my fix catches all cases? many thanks!

adam-fowler commented 3 years ago

jackmarch (JIRA User) I've edited the code to include where the warning appears.

kavon commented 2 years ago

Thanks for taking on the fix for this jackmarch (JIRA User). Feel free to add me as a reviewer for the PR for this on Github to get this merged in or if you need help, etc. My username is `kavon`.

swift-ci commented 2 years ago

Comment by Jack March (JIRA)

thanks Adam and Kavon! hopefully will get a chance to look at it Sunday

swift-ci commented 2 years ago

Comment by Jack March (JIRA)

@kavon trying to fix this but having some difficulty building the compiler, even deleted the entire repo locally and recloned but getting this message

jackmarch@Jacks-MacBook-Pro-2 swift % utils/build-script --skip-build-benchmarks \
  --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
  --sccache --release-debuginfo --swift-disable-dead-stripping --test
[utils/build-script] NOTE: Using toolchain default
Ensuring the sccache server is running...
+ /usr/local/bin/sccache --show-stats
+ /usr/libexec/PlistBuddy -c 'Print :SupportedTargets:macosx:Archs' '/Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/SDKSettings.plist'
+ mkdir -p /Users/jackmarch/swift-project/build/Ninja-RelWithDebInfoAssert
--- Building earlyswiftdriver ---
+ /Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py build --package-path /Users/jackmarch/swift-project/swift-driver --build-path /Users/jackmarch/swift-project/build/Ninja-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64 --configuration release --toolchain '/Applications/Xcode compiler.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr' --ninja-bin /usr/local/bin/ninja --cmake-bin /usr/local/bin/cmake --local_compiler_build
Building Swift Driver dependency: llbuild
CMake Error at /usr/local/Cellar/cmake/3.21.3/share/cmake/Modules/CMakeTestSwiftCompiler.cmake:44 (message):
  The Swift compiler

    "/Applications/Xcode compiler.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/jackmarch/swift-project/build/Ninja-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64/release/dependencies/llbuild/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/local/bin/ninja cmTC_d9ccc && [1/1][100%][0.019s] Linking Swift executable cmTC_d9ccc
    FAILED: cmTC_d9ccc CMakeFiles/cmTC_d9ccc.dir/main.swift.o cmTC_d9ccc.swiftmodule 
    : && "/Applications/Xcode compiler.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc" -output-file-map CMakeFiles/cmTC_d9ccc.dir//output-file-map.json -incremental -j 16 -emit-executable -o cmTC_d9ccc -emit-dependencies  -module-cache-path "/Users/jackmarch/swift-project/build/Ninja-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64/module-cache" -target x86_64-apple-macosx10.15 -sdk /Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk  -sdk "/Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk" -module-cache-path "/Users/jackmarch/swift-project/build/Ninja-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64/module-cache" -target x86_64-apple-macosx10.15 -sdk /Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk  -sdk "/Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk"  /Users/jackmarch/swift-project/build/Ninja-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64/release/dependencies/llbuild/CMakeFiles/CMakeTmp/main.swift    && :
    <unknown>:0: error: no such file or directory: 'compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk'
    <unknown>:0: error: no such file or directory: 'compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk'
    ninja: build stopped: subcommand failed.

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  products/CMakeLists.txt:8 (enable_language)

Traceback (most recent call last):
  File "/Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py", line 667, in <module>
    main()
  File "/Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py", line 664, in main
    handle_invocation(args)
  File "/Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py", line 194, in handle_invocation
    build_using_cmake(args, toolchain_bin, args.build_path, targets)
  File "/Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py", line 434, in build_using_cmake
    base_cmake_flags, swift_flags)
  File "/Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py", line 474, in build_llbuild_using_cmake
    llbuild_source_dir, llbuild_build_dir, 'products/all')
  File "/Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py", line 545, in cmake_build
    subprocess.check_output(cmd, cwd=build_dir)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 223, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['/usr/local/bin/cmake', '-G', 'Ninja', '-DCMAKE_MAKE_PROGRAM=/usr/local/bin/ninja', '-DCMAKE_BUILD_TYPE:=Release', u'-DCMAKE_Swift_FLAGS=-module-cache-path "/Users/jackmarch/swift-project/build/Ninja-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64/module-cache" -target x86_64-apple-macosx10.15 -sdk /Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk', '-DCMAKE_Swift_COMPILER:=/Applications/Xcode compiler.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc', '-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15', '-DCMAKE_C_COMPILER:=clang', '-DCMAKE_CXX_COMPILER:=clang++', u'-DCMAKE_CXX_FLAGS=-target x86_64-apple-macosx10.15', '-DLLBUILD_SUPPORT_BINDINGS:=Swift', u'-DCMAKE_OSX_ARCHITECTURES=x86_64', '-DSQLite3_INCLUDE_DIR=/Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include', '-DSQLite3_LIBRARY=/Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/lib/libsqlite3.tbd', '/Users/jackmarch/swift-project/llbuild']' returned non-zero exit status 1
ERROR: command terminated with a non-zero exit status 1, aborting

Slightly different error when trying to build Xcode version:

jackmarch@Jacks-MacBook-Pro-2 swift % utils/build-script --skip-build-benchmarks \
  --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
  --sccache --release-debuginfo --swift-disable-dead-stripping --test \
  --xcode
[utils/build-script] NOTE: Using toolchain default
Ensuring the sccache server is running...
+ /usr/local/bin/sccache --show-stats
+ /usr/libexec/PlistBuddy -c 'Print :SupportedTargets:macosx:Archs' '/Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/SDKSettings.plist'
+ mkdir -p /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert
--- Building earlyswiftdriver ---
+ /Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py build --package-path /Users/jackmarch/swift-project/swift-driver --build-path /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64 --configuration release --toolchain '/Applications/Xcode compiler.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr' --ninja-bin /usr/local/bin/ninja --cmake-bin /usr/local/bin/cmake --local_compiler_build
Building Swift Driver dependency: llbuild
CMake Error at /usr/local/Cellar/cmake/3.21.3/share/cmake/Modules/CMakeTestSwiftCompiler.cmake:44 (message):
  The Swift compiler

    "/Applications/Xcode compiler.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64/release/dependencies/llbuild/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/local/bin/ninja cmTC_114eb && [1/1][100%][0.017s] Linking Swift executable cmTC_114eb
    FAILED: cmTC_114eb CMakeFiles/cmTC_114eb.dir/main.swift.o cmTC_114eb.swiftmodule 
    : && "/Applications/Xcode compiler.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc" -output-file-map CMakeFiles/cmTC_114eb.dir//output-file-map.json -incremental -j 16 -emit-executable -o cmTC_114eb -emit-dependencies  -module-cache-path "/Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64/module-cache" -target x86_64-apple-macosx10.15 -sdk /Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk  -sdk "/Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk" -module-cache-path "/Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64/module-cache" -target x86_64-apple-macosx10.15 -sdk /Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk  -sdk "/Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk"  /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64/release/dependencies/llbuild/CMakeFiles/CMakeTmp/main.swift    && :
    <unknown>:0: error: no such file or directory: 'compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk'
    <unknown>:0: error: no such file or directory: 'compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk'
    ninja: build stopped: subcommand failed.

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  products/CMakeLists.txt:8 (enable_language)

Traceback (most recent call last):
  File "/Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py", line 667, in <module>
    main()
  File "/Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py", line 664, in main
    handle_invocation(args)
  File "/Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py", line 194, in handle_invocation
    build_using_cmake(args, toolchain_bin, args.build_path, targets)
  File "/Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py", line 434, in build_using_cmake
    base_cmake_flags, swift_flags)
  File "/Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py", line 474, in build_llbuild_using_cmake
    llbuild_source_dir, llbuild_build_dir, 'products/all')
  File "/Users/jackmarch/swift-project/swift-driver/Utilities/build-script-helper.py", line 545, in cmake_build
    subprocess.check_output(cmd, cwd=build_dir)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 223, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['/usr/local/bin/cmake', '-G', 'Ninja', '-DCMAKE_MAKE_PROGRAM=/usr/local/bin/ninja', '-DCMAKE_BUILD_TYPE:=Release', u'-DCMAKE_Swift_FLAGS=-module-cache-path "/Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64/module-cache" -target x86_64-apple-macosx10.15 -sdk /Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk', '-DCMAKE_Swift_COMPILER:=/Applications/Xcode compiler.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc', '-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15', '-DCMAKE_C_COMPILER:=clang', '-DCMAKE_CXX_COMPILER:=clang++', u'-DCMAKE_CXX_FLAGS=-target x86_64-apple-macosx10.15', '-DLLBUILD_SUPPORT_BINDINGS:=Swift', u'-DCMAKE_OSX_ARCHITECTURES=x86_64', '-DSQLite3_INCLUDE_DIR=/Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include', '-DSQLite3_LIBRARY=/Applications/Xcode compiler.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/lib/libsqlite3.tbd', '/Users/jackmarch/swift-project/llbuild']' returned non-zero exit status 1
ERROR: command terminated with a non-zero exit status 1, aborting
swift-ci commented 2 years ago

Comment by Jack March (JIRA)

I'm going to unassigned from myself for the mean time unless I'm able to build the compiler again.

For others' context, this is not just a problem with enum's. it seems the problem is the warning occurs even in cases where member `self` is prefixed with a dot. .self is not confusable with "self", so I suggest we don't show the warning cases where it's prefixed with a dot:

enum EnumWithSelfCase {
    var property: EnumWithSelfCase {
        .self // error here
    }
    case `self`
}

struct TypeWithSelfFunc {
    static func `self`() {
    }
}
class TypeWithDemoProperties {
    let z = EnumWithSelfCase.`self` // error here
    let x = TypeWithSelfFunc.`self` // error here
}