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

Odd bug regarding types in member expressions. #350

Open
7ombie opened this issue Feb 8, 2024 · 3 comments
Open

Odd bug regarding types in member expressions. #350

7ombie opened this issue Feb 8, 2024 · 3 comments

Comments

@7ombie
Copy link

7ombie commented Feb 8, 2024

There are some cases where the types (MemoryLayout and Float) are not highlighted as types in the following expression:

MemoryLayout<Float>.stride

In other (most) cases, the types are highlighted correctly. The simplest (and oddest) example I could find was the following:

let a = MemoryLayout<Float>.stride
let b = MemoryLayout<Float>.stride + 1

In the first line, the types are not highlighted, while on the second line they are.

Note: I'm working with Helix (trying to update their Swift support), and came across this issue there. I'm assuming it's upstream, as their highlights.scm file is not very different from yours (despite being well over a year out of sync).

@alex-pinkus
Copy link
Owner

This is odd indeed. I’m going to baselessly speculate that we’re parsing as (MemoryLayout < Float) > (.stride) (i.e. comparison operators). I have to think a bit about how we would restructure the precedence to handle that properly.

@7ombie
Copy link
Author

7ombie commented Feb 9, 2024

Thanks for looking into it for us. It's not urgent. Just bringing it to your attention really.

Thanks for all your hard work. Much appreciated.

@bbb651
Copy link

bbb651 commented Aug 10, 2024

I asked a question regarding this on the swift forums and got a very helpful response, linking me to this function that does a lookahead to decide if it can parse it as a generic arguments list, it first parses the generic arguments list and does checks for the next token:

extension Lexer.Lexeme {
  var isGenericTypeDisambiguatingToken: Bool {
    switch self.rawTokenKind {
    case .rightParen,
      .rightSquare,
      .leftBrace,
      .rightBrace,
      .period,
      .comma,
      .semicolon,
      .endOfFile,
      .exclamationMark,
      .postfixQuestionMark,
      .colon:
      return true
    case .binaryOperator:
      return self.tokenText == "&"
    case .postfixOperator:
      return false
    case .leftParen, .leftSquare:
      // These only apply to the generic type if they don't start a new line.
      return !self.isAtStartOfLine
    default:
      return false
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants