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

Unexpected compiler error for CharacterClass.inverted #672

Open
Kyle-Ye opened this issue May 21, 2023 · 3 comments
Open

Unexpected compiler error for CharacterClass.inverted #672

Kyle-Ye opened this issue May 21, 2023 · 3 comments
Assignees

Comments

@Kyle-Ye
Copy link

Kyle-Ye commented May 21, 2023

inverted defined in CharacterClass will return CharacterClass. But the compiler is emitting an error for it.

let a0 = OneOrMore(.anyOf("a")) // ✅
let a1 = OneOrMore(.anyOf("a").inverted) // ❌(Unexpected) Member 'inverted' in 'CharacterClass' produces result of type 'RegexComponent', but context expects 'CharacterClass'
let a2 = OneOrMore(CharacterClass.anyOf("a").inverted) // ✅
@Kyle-Ye
Copy link
Author

Kyle-Ye commented May 21, 2023

Looks like this is an issue on the swift Compiler side. I think it was matched to Anchor.inverted which lead to the problem. But actually .anyOf will only return CharacterClass

@milseman
Copy link
Member

@natecook1000 have you seen anything like this before?

@natecook1000
Copy link
Member

natecook1000 commented May 24, 2023

I have not! Looks like there might be some interference between SE-0287 and SE-0299? I'll try a reduced example.

Edit: This is pretty much the RegexBuilder setup, but doesn't reproduce the problem. Am I missing something? We don't even have the Anchor extension methods that would allow it to be selected in that some RegexComponent context.

protocol MyComponent {}

func takesMyComponent(_ c: some MyComponent) {
  print(c)
}

struct MyCharacterClass: MyComponent {
  var id: Int
  
  var inverted: MyCharacterClass {
    MyCharacterClass(id: -self.id)
  }
}

struct MyAnchor: MyComponent {
  var id: Int
  
  var inverted: MyAnchor {
    MyAnchor(id: -self.id)
  }
}

extension MyComponent where Self == MyCharacterClass {
  static func anyOf(_ id: Int) -> MyCharacterClass {
    MyCharacterClass(id: id)
  }
}

takesMyComponent(.anyOf(1).inverted)
takesMyComponent(MyAnchor(id: 2).inverted)

I'm able to reproduce @Kyle-Ye's report with both Swift 5.8 and 5.9…

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