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-6207] Misleading error for unqualified use of static variable in method #48759

Open
huonw mannequin opened this issue Oct 24, 2017 · 7 comments
Open

[SR-6207] Misleading error for unqualified use of static variable in method #48759

huonw mannequin opened this issue Oct 24, 2017 · 7 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers

Comments

@huonw
Copy link
Mannequin

huonw mannequin commented Oct 24, 2017

Previous ID SR-6207
Radar rdar://problem/24291352
Original Reporter @huonw
Type Bug
Status In Progress
Resolution
Environment

Swift 4

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug
Assignee None
Priority Medium

md5: 47c00d1618aecdca414e977e2fbf19c9

Issue Description:

struct HasStatic {
    func foo() {
        print(cvar)
    }
    static let cvar = 123
}

hasstatic.swift:3:11: error: static member 'cvar' cannot be used on instance of type 'HasStatic'
    print(cvar)
          ^~~~
          HasStatic.

The fixit helps, but it still isn't obvious what's going wrong. The compiler is acting like the use of cvar was written self.cvar, and hints at this with "an instance of", but it's easy to gloss over the subtlety. The text could be tweaked, maybe like

static member 'cvar' can only be used on the type 'HasStatic', not the instance 'X'

where the X is the relevant parent value. (e.g. self for this case, or foo.bar for foo.bar.cvar).

@belkadan
Copy link
Contributor

The starter bug form of this would be to only include the name if the base expression was a simple DeclRefExpr, or perhaps also a MemberRefExpr. Using the Expr::getSemanticsProvidingExpr helper will make it work with parentheses as well.

@swift-ci
Copy link
Collaborator

Comment by Oscar Swanros (JIRA)

Will give this one a go. Made the changes, waiting for the tests to complete on my machine.

@swift-ci
Copy link
Collaborator

Comment by Oscar Swanros (JIRA)

utils/build-script --test is failing even on a clean repo download with CMake errors...

CMake Error at cmake/modules/AddSwift.cmake:24 (add_dependencies):
The dependency target "clang-tablegen-targets" of target "swiftAST" does
not exist.
Call Stack (most recent call first):
cmake/modules/AddSwift.cmake:987 (add_dependencies_multiple_targets)
cmake/modules/AddSwift.cmake:1789 (_add_swift_library_single)
lib/AST/CMakeLists.txt:6 (add_swift_library)

Any idea on what could be going on here? Maybe I have some misconfiguration?

@belkadan
Copy link
Contributor

I think that means your Clang is out of date. When was the last time you updated your Clang and LLVM repos?

@swift-ci
Copy link
Collaborator

Comment by Oscar Swanros (JIRA)

Uh, good question. Updated both repos and tried to recompile. This time I got a little bit further, but got another error.

#12644 — Opened the PR so I could share progress and maybe get some pointers. I think the way I'm checking for DeclRefExpr is not right.

@swift-ci
Copy link
Collaborator

Comment by Oscar Swanros (JIRA)

I think the PR is ready for review!

@belkadan
Copy link
Contributor

Oops, it looks like we lost this one at the time.

Resetting assignee on all Starter Bugs last modified in 2018. If someone wants to pick up swanros (JIRA User)'s PR, they're welcome to! (Including swanros (JIRA User).)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants