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-7562] @discardableResult is disregarded for a required init method #50104
Comments
I'm inclined to agree! Tagging as a StarterBug. The fix would be changing |
hello Vandad (JIRA User) and @belkadan . I took the liberty of assigning the bug to myself. I am new to the swift compiler and was looking at starter bugs I could help with and I think i can tackle this one 🙂. |
Welcome, Victor! Feel free to open a pull request on GitHub as soon as you have something ready for initial review, or even if you just have questions as you go. |
thanks Jordan! I followed your prev. comment and I got a fix already. I am currently writing a test that makes sure the warning is not emitted but can't manage to execute it locally. Maybe you can give me a hand here 🙂. I am launching the test as follows: ./llvm/utils/lit/lit.py -svv ./build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/test-macosx-x86_64/attr --filter=attr_discardableResult.swift --param swift-version=4 -a test fails with following stack trace: Unable to find source-code formatter for language: python. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xmlTraceback (most recent call last):
File "/Volumes/VicDrive/ML/swift-tensorflow/llvm/utils/lit/lit/run.py", line 202, in _execute_test_impl
result = test.config.test_format.execute(test, lit_config)
File "/Volumes/VicDrive/ML/swift-tensorflow/swift/test/swift_test.py", line 63, in execute
result = super(SwiftTest, self).execute(test, litConfig)
File "/Volumes/VicDrive/ML/swift-tensorflow/llvm/utils/lit/lit/formats/shtest.py", line 25, in execute
self.execute_external)
File "/Volumes/VicDrive/ML/swift-tensorflow/llvm/utils/lit/lit/TestRunner.py", line 1478, in executeShTest
script = applySubstitutions(script, substitutions)
File "/Volumes/VicDrive/ML/swift-tensorflow/llvm/utils/lit/lit/TestRunner.py", line 1178, in applySubstitutions
return list(map(processLine, script))
File "/Volumes/VicDrive/ML/swift-tensorflow/llvm/utils/lit/lit/TestRunner.py", line 1172, in processLine
ln = re.sub(a, b, ln)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 155, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 286, in _subx
template = _compile_repl(template, pattern)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 271, in _compile_repl
p = sre_parse.parse_template(repl, pattern)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_parse.py", line 737, in parse_template
s = Tokenizer(source)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_parse.py", line 192, in __init__
self.__next()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_parse.py", line 194, in __next
if self.index >= len(self.string):
TypeError: object of type 'NoneType' has no len() i added some print statements in `TestRunner.py` to understand a bit more what is going on and I see that failure happens when applying substitution for : `%target-swift-reflection-test` am I forgetting to set an environment variable? or maybe passing a parameter to the lit.py script? Thank you for your help in advance! |
Ah, for an Xcode build I believe you have to pass |
(Bug-to-file: have lit check if you're in an Xcode build and complain directly if so.) |
thank you Jordan! That made it work. about your last comment, do you want me to file a bug for that? |
Heh, you're welcome to. I'll get to it if you don't. |
thanks for creating SR-7714 🙂 .. it would be indeed a nice improvement. |
PR that solves this issue has been merged. |
Pulling into the 4.2 branch, since it's a small, safe change: #16796 |
Environment
swift --version
Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)
Target: x86_64-apple-darwin17.5.0
Additional Detail from JIRA
md5: bddad59f549a8118d77ef9d4bf5040fb
Issue Description:
My problem is sort of related to the following issue: SR-2198
Consider the following example:
If I instantiate Foo, with its init method marked with @discardableResult, then the compiler does a good job of not warning me about the unused result.
However, if I instantiate Bar, who inherits its init method from Foo, I will get a warning:
I believe this to be a bug and not a feature since Bar can and should inherit its init method from Foo to be able to get the same effect as Foo has.
The text was updated successfully, but these errors were encountered: