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-3296] swift build doesn't use a case-insensitive compare when checking for filename conflicts #45884

Open
gfontenot opened this issue Nov 30, 2016 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@gfontenot
Copy link

Previous ID SR-3296
Radar None
Original Reporter @gfontenot
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: da8f13d1a3b3ac5b00cfd629e956aa13

Issue Description:

If a package has multiple files named the same way, swift build will fail to compile the package and throws a helpful error:

Compile Swift Module 'Bug' (2 sources)
<unknown>:0: error: filename "Foo.swift" used twice: '/Users/gordon/Code/gfontenot/SwiftPMCaseBug/Sources/Bug/Bar/Foo.swift' and '/Users/gordon/Code/gfontenot/SwiftPMCaseBug/Sources/Bug/Foo/Foo.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/gordon/Code/gfontenot/SwiftPMCaseBug/.build/debug.yaml}}

However, if the files have the same name with a different case, swift build fails to catch the conflict and successfully builds the package:

mv Sources/Bug/Bar/Foo.swift Sources/Bug/Bar/foo.swifttree Sources
Sources
└── Bug
    ├── Bar
    │   └── foo.swift
    └── Foo
        └── Foo.swift

3 directories, 2 filesswift build
Compile Swift Module 'Bug' (2 sources)
❯

The end result of this is that when end-users attempt to use the functions/types defined in those conflicting files, they get a fairly confusing error message in the consuming code:

swift build
Compile Swift Module 'Test' (1 sources)
/Users/gordon/Code/gfontenot/SwiftPMCaseBug/test/Sources/main.swift:3:1: error: ambiguous use of 'foo()'
foo()
^
Bug.foo:1:13: note: found this candidate
public func foo()
            ^
Bug.foo:1:13: note: found this candidate
public func foo()
            ^
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/gordon/Code/gfontenot/SwiftPMCaseBug/test/.build/debug.yaml

I believe the simplest fix for this would be to ensure that we're using a case-insensitive compare when checking for filename conflicts.

I've uploaded a minimal case to reproduce the bug on my GitHub.

@ddunbar
Copy link
Member

ddunbar commented Nov 30, 2016

This is actually a Swift driver diagnostic, not a package manager one. @belkadan?

@belkadan
Copy link
Contributor

The names of your files have nothing to do with the names of the declarations in them. Having two files that differ only by case is fine as far as the compiler or package manager are concerned. If there is a bug here, it's that the contents of the files aren't being checked properly.

(In other words, this error would happen even if you named the files Foo.swift and Bar.swift.)

@gfontenot
Copy link
Author

@belkadan Sorry, I don't follow, and that doesn't seem to be what the sample is demonstrating. In the sample, `Foo.swift` is defining `public func foo()`, while `foo.swift` is defining `public func bar()`. Renaming `foo.swift` to `Bar.swift` fixes the bug:

mv Sources/Bug/Bar/foo.swift Sources/Bug/Bar/Bar.swifttree Sources
Sources
└── Bug
    ├── Bar
    │   └── Bar.swift
    └── Foo
        └── Foo.swift

3 directories, 2 filesswift build
Compile Swift Module 'Bug' (2 sources)
# snipcd testswift build
HEAD is now at 2badf83 fix
Resolved version: 1.1.0
Compile Swift Module 'Bug' (2 sources)
Compile Swift Module 'Test' (1 sources)
Linking ./.build/debug/Test

@belkadan
Copy link
Contributor

Oh, I'm sorry, I missed that because I didn't see how it was possible. Bizarre.

@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
Projects
None yet
Development

No branches or pull requests

3 participants