Skip to content
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

[SR-3936] Provide a Fix It for errors such as "Computed property must have an explicit type" #46521

Closed
swift-ci opened this issue Feb 11, 2017 · 5 comments
Assignees
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers improvement

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-3936
Radar None
Original Reporter elia (JIRA User)
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, StarterBug
Assignee @hartbit
Priority Medium

md5: 9023757e88cd437914deadb3e6f97e38

Issue Description:

I think it would be nice to have a Fix It for this kind of errors, for example trying to infer the correct type from the body of the computed property. Since automatic inference isn't applied here, it would be useful to at least try applying it and make the inferred type available to the developer.

Personal example: I have written computed properties to alias properties on other objects, as a faster way to access them. I often don't know / I'm too lazy to remember the type of the property I'm aliasing, so I'd like the convenience of just writing the body of the computed property and have the compiler figure out the type for me.

I haven't searched yet for other errors where this might apply, nor I've looked at possible implementations. I'd like an indication on this part from someone with more experience on the compiler structure, but if this is something that's deemed nice to have I'd be happy to help in the implementation.

@belkadan
Copy link
Contributor

This diagnostic predates us putting editor placeholders in fix-its, but now that that's becoming more common it does make sense here. Tagging as a good starter bug.

@swift-ci
Copy link
Collaborator Author

Comment by Elia Cereda (JIRA)

If I understand correctly, what you're proposing is slightly different from what I had in mind. Let's say we start from this piece of code:

class A {
  static let shared = A()
}

class B {
   var a { return A.shared }
}

Are you proposing to fix-it to this?

  var a: <# Type #> { return A.shared }

Wouldn't it be possible in this case to actually fix-it to this, since the getter already provides an indication of the type of the property?

  var a: A { return A.shared }

@belkadan
Copy link
Contributor

Ah, that might work in simple cases. I was concerned about cases that rely on inferring something from context, i.e. the body of the getter might not be unambiguous. (It might also have multiple return statements, in which I'd rather not have the compiler try to pick a common type.) But in the case of a single return statement it might make sense to run the type-checker on the expression and see what type we'd get.

@swift-ci
Copy link
Collaborator Author

Comment by Elia Cereda (JIRA)

I'm trying to build Swift but I'm getting the following error almost immediately:

+ mkdir -p /Volumes/Documenti/Applicazioni/swift-compiler/build/Ninja-DebugAssert
+ env HOST_VARIABLE_macosx_x86_64__SWIFT_BENCHMARK_TARGETS=swift-benchmark-macosx-x86_64 HOST_VARIABLE_macosx_x86_64__SWIFT_RUN_BENCHMARK_TARGETS=check-swift-benchmark-macosx-x86_64 'HOST_VARIABLE_macosx_x86_64__SWIFT_SDKS=IOS IOS_SIMULATOR OSX TVOS TVOS_SIMULATOR WATCHOS WATCHOS_SIMULATOR' HOST_VARIABLE_macosx_x86_64__SWIFT_STDLIB_TARGETS=swift-test-stdlib-macosx-x86_64 HOST_VARIABLE_macosx_x86_64__SWIFT_TEST_TARGETS= caffeinate /Volumes/Documenti/Applicazioni/swift-compiler/swift/utils/build-script-impl --workspace /Volumes/Documenti/Applicazioni/swift-compiler --build-dir /Volumes/Documenti/Applicazioni/swift-compiler/build/Ninja-DebugAssert --install-prefix /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr --host-target macosx-x86_64 --stdlib-deployment-targets 'macosx-x86_64 iphonesimulator-i386 iphonesimulator-x86_64 appletvsimulator-x86_64 watchsimulator-i386 iphoneos-armv7 iphoneos-armv7s iphoneos-arm64 appletvos-arm64 watchos-armv7k' --host-cc '/Volumes/Documenti/Applicazioni/Xcode 8.3b2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' --host-cxx '/Volumes/Documenti/Applicazioni/Xcode 8.3b2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++' --darwin-xcrun-toolchain default --darwin-deployment-version-osx=10.9 --darwin-deployment-version-ios=7.0 --darwin-deployment-version-tvos=9.0 --darwin-deployment-version-watchos=2.0 --cmake /usr/local/bin/cmake --cmark-build-type Debug --llvm-build-type Debug --swift-build-type Debug --swift-stdlib-build-type Debug --lldb-build-type Debug --foundation-build-type Debug --libdispatch-build-type Debug --libicu-build-type Debug --xctest-build-type Debug --swiftpm-build-type Debug --swift-enable-assertions true --swift-stdlib-enable-assertions true --swift-analyze-code-coverage false --cmake-generator Ninja --build-jobs 4 '--common-cmake-options=-G Ninja '"'"'-DCMAKE_C_COMPILER:PATH=/Volumes/Documenti/Applicazioni/Xcode 8.3b2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang'"'"' '"'"'-DCMAKE_CXX_COMPILER:PATH=/Volumes/Documenti/Applicazioni/Xcode 8.3b2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++'"'"' -DCMAKE_MAKE_PROGRAM=/usr/local/bin/ninja' '--build-args=-j4 -v' --cmark-cmake-options= '--llvm-cmake-options=-DLLVM_ENABLE_ASSERTIONS=TRUE -DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64;PowerPC;SystemZ' '--swift-cmake-options=-DSWIFT_STDLIB_ENABLE_SIL_OWNERSHIP=FALSE -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE -DSWIFT_FORCE_OPTIMIZED_TYPECHECKER=FALSE' --build-stdlib-deployment-targets all --ninja-bin=/usr/local/bin/ninja --verbose-build --skip-build-foundation --skip-build-xctest --skip-build-lldb --skip-build-llbuild --skip-build-libdispatch --skip-build-libicu --skip-build-swiftpm --skip-build-playgroundlogger --skip-build-playgroundsupport --build-swift-dynamic-stdlib --build-swift-dynamic-sdk-overlay --skip-build-ios-device --skip-build-ios-simulator --skip-build-tvos-device --skip-build-tvos-simulator --skip-build-watchos-device --skip-build-watchos-simulator --skip-build-android --skip-test-swift --skip-test-cmark --skip-test-lldb --skip-test-llbuild --skip-test-swiftpm --skip-test-xctest --skip-test-foundation --skip-test-libdispatch --skip-test-libicu --skip-test-playgroundlogger --skip-test-playgroundsupport --skip-test-linux --skip-test-freebsd --skip-test-cygwin --skip-test-osx --skip-test-ios-host --skip-test-ios-simulator --skip-test-tvos-host --skip-test-tvos-simulator --skip-test-watchos-host --skip-test-watchos-simulator --skip-test-android-host --skip-test-benchmarks --skip-test-optimized --android-deploy-device-path /data/local/tmp --toolchain-prefix /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain --host-lipo '/Volumes/Documenti/Applicazioni/Xcode 8.3b2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo' --host-libtool '/Volumes/Documenti/Applicazioni/Xcode 8.3b2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool' --llvm-lit-args=-sv
Building the standard library for: swift-test-stdlib-macosx-x86_64
cmark: using standard linker
+ /usr/local/bin/cmake --build /Volumes/Documenti/Applicazioni/swift-compiler/build/Ninja-DebugAssert/cmark-macosx-x86_64 -- -j4 -v all
ninja: no work to do.
llvm: using standard linker
usage: dirname path
utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting

Maybe off-topic here, does this need a proper issue?

@belkadan
Copy link
Contributor

Haven't seen that one before. Yeah, can you either file a separate bug or ask on swift-dev?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers improvement
Projects
None yet
Development

No branches or pull requests

2 participants