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-10486] [SourceKit][Regression] Variable missing from structure on Swift 5 #52886

Closed
marcelofabri opened this issue Apr 15, 2019 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. regression swift 5.0

Comments

@marcelofabri
Copy link
Contributor

Previous ID SR-10486
Radar rdar://49906932
Original Reporter @marcelofabri
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0

Additional Detail from JIRA
Votes 0
Component/s Source Tooling
Labels Bug, 5.0Regression
Assignee None
Priority Medium

md5: 8456c55040df4136ca448a8bb137442a

Issue Description:

For this file,

private let nonSpace = "[^ ]"
private let twoOrMoreSpace = " {2,}"
private let mark = "MARK:"
private let nonSpaceOrTwoOrMoreSpace = "(?:\(nonSpace)|\(twoOrMoreSpace))"
private let nonSpaceOrTwoOrMoreSpaceOrNewline = "(?:[^ \n]|\(twoOrMoreSpace))"

The last variable is missing on SourceKit structure, here obtained with SourceKitten:

{
  "key.diagnostic_stage" : "source.diagnostic.stage.swift.parse",
  "key.length" : 248,
  "key.offset" : 0,
  "key.substructure" : [
    {
      "key.accessibility" : "source.lang.swift.accessibility.private",
      "key.attributes" : [
        {
          "key.attribute" : "source.decl.attribute.private",
          "key.length" : 7,
          "key.offset" : 0
        }
      ],
      "key.kind" : "source.lang.swift.decl.var.global",
      "key.length" : 21,
      "key.name" : "nonSpace",
      "key.namelength" : 8,
      "key.nameoffset" : 12,
      "key.offset" : 8
    },
    {
      "key.accessibility" : "source.lang.swift.accessibility.private",
      "key.attributes" : [
        {
          "key.attribute" : "source.decl.attribute.private",
          "key.length" : 7,
          "key.offset" : 30
        }
      ],
      "key.kind" : "source.lang.swift.decl.var.global",
      "key.length" : 28,
      "key.name" : "twoOrMoreSpace",
      "key.namelength" : 14,
      "key.nameoffset" : 42,
      "key.offset" : 38
    },
    {
      "key.accessibility" : "source.lang.swift.accessibility.private",
      "key.attributes" : [
        {
          "key.attribute" : "source.decl.attribute.private",
          "key.length" : 7,
          "key.offset" : 67
        }
      ],
      "key.kind" : "source.lang.swift.decl.var.global",
      "key.length" : 18,
      "key.name" : "mark",
      "key.namelength" : 4,
      "key.nameoffset" : 79,
      "key.offset" : 75
    },
    {
      "key.accessibility" : "source.lang.swift.accessibility.private",
      "key.attributes" : [
        {
          "key.attribute" : "source.decl.attribute.private",
          "key.length" : 7,
          "key.offset" : 94
        }
      ],
      "key.kind" : "source.lang.swift.decl.var.global",
      "key.length" : 66,
      "key.name" : "nonSpaceOrTwoOrMoreSpace",
      "key.namelength" : 24,
      "key.nameoffset" : 106,
      "key.offset" : 102
    },
    {
      "key.bodylength" : 0,
      "key.bodyoffset" : 168,
      "key.kind" : "source.lang.swift.stmt.brace",
      "key.length" : 42,
      "key.namelength" : 0,
      "key.nameoffset" : 0,
      "key.offset" : 133,
      "key.substructure" : [
        {
          "key.bodylength" : 8,
          "key.bodyoffset" : 139,
          "key.kind" : "source.lang.swift.expr.call",
          "key.length" : 10,
          "key.namelength" : 0,
          "key.nameoffset" : 0,
          "key.offset" : 138
        },
        {
          "key.bodylength" : 14,
          "key.bodyoffset" : 151,
          "key.kind" : "source.lang.swift.expr.call",
          "key.length" : 16,
          "key.namelength" : 0,
          "key.nameoffset" : 0,
          "key.offset" : 150
        }
      ]
    },
    {
      "key.bodylength" : 0,
      "key.bodyoffset" : 247,
      "key.kind" : "source.lang.swift.stmt.brace",
      "key.length" : 30,
      "key.namelength" : 0,
      "key.nameoffset" : 0,
      "key.offset" : 217,
      "key.substructure" : [
        {
          "key.bodylength" : 14,
          "key.bodyoffset" : 230,
          "key.kind" : "source.lang.swift.expr.call",
          "key.length" : 16,
          "key.namelength" : 0,
          "key.nameoffset" : 0,
          "key.offset" : 229
        }
      ]
    }
  ]
}

If I use Swift 4.2 from Xcode 10.1 instead, the variable is there:

{
  "key.diagnostic_stage" : "source.diagnostic.stage.swift.parse",
  "key.length" : 248,
  "key.offset" : 0,
  "key.substructure" : [
    {
      "key.accessibility" : "source.lang.swift.accessibility.private",
      "key.attributes" : [
        {
          "key.attribute" : "source.decl.attribute.private",
          "key.length" : 7,
          "key.offset" : 0
        }
      ],
      "key.kind" : "source.lang.swift.decl.var.global",
      "key.length" : 21,
      "key.name" : "nonSpace",
      "key.namelength" : 8,
      "key.nameoffset" : 12,
      "key.offset" : 8
    },
    {
      "key.accessibility" : "source.lang.swift.accessibility.private",
      "key.attributes" : [
        {
          "key.attribute" : "source.decl.attribute.private",
          "key.length" : 7,
          "key.offset" : 30
        }
      ],
      "key.kind" : "source.lang.swift.decl.var.global",
      "key.length" : 28,
      "key.name" : "twoOrMoreSpace",
      "key.namelength" : 14,
      "key.nameoffset" : 42,
      "key.offset" : 38
    },
    {
      "key.accessibility" : "source.lang.swift.accessibility.private",
      "key.attributes" : [
        {
          "key.attribute" : "source.decl.attribute.private",
          "key.length" : 7,
          "key.offset" : 67
        }
      ],
      "key.kind" : "source.lang.swift.decl.var.global",
      "key.length" : 18,
      "key.name" : "mark",
      "key.namelength" : 4,
      "key.nameoffset" : 79,
      "key.offset" : 75
    },
    {
      "key.accessibility" : "source.lang.swift.accessibility.private",
      "key.attributes" : [
        {
          "key.attribute" : "source.decl.attribute.private",
          "key.length" : 7,
          "key.offset" : 94
        }
      ],
      "key.kind" : "source.lang.swift.decl.var.global",
      "key.length" : 66,
      "key.name" : "nonSpaceOrTwoOrMoreSpace",
      "key.namelength" : 24,
      "key.nameoffset" : 106,
      "key.offset" : 102
    },
    {
      "key.accessibility" : "source.lang.swift.accessibility.private",
      "key.attributes" : [
        {
          "key.attribute" : "source.decl.attribute.private",
          "key.length" : 7,
          "key.offset" : 169
        }
      ],
      "key.kind" : "source.lang.swift.decl.var.global",
      "key.length" : 70,
      "key.name" : "nonSpaceOrTwoOrMoreSpaceOrNewline",
      "key.namelength" : 33,
      "key.nameoffset" : 181,
      "key.offset" : 177
    }
  ]
}
@belkadan
Copy link
Contributor

Weird. @benlangmuir, any ideas?

@benlangmuir
Copy link
Member

Looks like we're losing the variable declaration after a string-interpolation.

private let a = "" // OK
private let b = "\(a)" // OK
private let c = "b" // Missing
private let d = "c" // OK

We are also adding the implicit brace-stmt from the interpolation and calls to interpolation functions to the structure, which seems bogus.

@jpsim
Copy link
Contributor

jpsim commented Sep 13, 2019

Was this fixed by #26354 ? @nathawes

@nathawes
Copy link
Collaborator

Looks like it. The issue no longer reproduces with recent development snapshots.

@nathawes
Copy link
Collaborator

This was caused by the same issue as SR-11099, fixed in #26354 It no longer reproduces with recent development snapshots.

@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
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. regression swift 5.0
Projects
None yet
Development

No branches or pull requests

6 participants