Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
pike
pike
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 106
    • Issues 106
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • pikelang
  • pikepike
  • Issues
  • #1311

Closed
Open
Opened Mar 13, 2001 by Peter Bortas@zinoOwner

Too optimistic static binding in switch

Imported from http://bugzilla.roxen.com/bugzilla/show_bug.cgi?id=1311

Reported by Martin Stjernholm mast@roxen.com

The following program could reasonably be expected to either produce a compilation error or write "1":

    class A
    {
      constant foo = 17;
      int x (int i)
      {
	switch (i) {
	  // On the following line, foo is bound as if being local
	  // (i.e. statically).
	  case foo: return 1;
	  default: return 0;
	}
      }
    }

    class B
    {
      inherit A;
      constant foo = 19;
    }

    int main()
    {
      werror ("%O\n", B()->x (19));
    }

The problem is that switch merrily resolves the constant expression "foo" to 17, without considering the situation where the constant is overridden in an inheriting class. In other words, in all switch labels, any constant identifier is bound as if it were implicitly preceded by "local::".

I think that's nonintuitive; it ought to be necessary to either declare the constant as local or final, or use "local::" in front of it when used as a switch label.

This problem exists at least in 7.0 and later, but it obviously cannot be changed without introducing compatibility problems.

Assignee
Assign to
Pike 7.4
Milestone
Pike 7.4
Assign milestone
Time tracking
None
Due date
None
Reference: pikelang/pike#1311