Uploaded image for project: 'Swift'
  1. Swift
  2. SR-1379

Swift Package Manager and main.swift

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler, Package Manager
    • Labels:
      None
    • Environment:

      Description

      Hi there,

      I was advised to post this as a bug report. This was originally an email out to the Swift Users mailing list.

      This is what happened as I was trying out the Swift Package Manager for another project similar to the one shown below:

      ~ $ mkdir example
      ~ $ cd example/
      example $ touch Package.swift
      example $ mkdir Sources
      example $ vi Sources/Example.swift
      example $ cat Sources/Example.swift
      func printOther() {
        print("other")
      }
      example $ vi Sources/Main.swift
      example $ cat Sources/Main.swift
      print("Hello World")
      printOther()
      
      example $ swift build
      Compile Swift Module 'example' (2 sources)
      /PATH/example/Sources/Main.swift:1:1: error: expressions are not allowed at the top level
      print("Hello World")
      ^
      /PATH/example/Sources/Main.swift:2:1: error: expressions are not allowed at the top level
      printOther()
      ^
      /PATH/example/Sources/Main.swift:1:1: error: expressions are not allowed at the top level
      print("Hello World")
      ^
      /PATH/example/Sources/Main.swift:2:1: error: expressions are not allowed at the top level
      printOther()
      ^
      <unknown>:0: error: build had 1 command failures
      error: exit(1): /PATH-SWIFT/usr/bin/swift-build-tool -f /PATH/example/.build/debug.yaml
      
      example $ mv Sources/Main.swift Sources/main.swift
      example $ swift build
      Compile Swift Module 'example' (2 sources)
      Linking .build/debug/example
      example $ .build/debug/example
      Hello World
      other
      example $
      

      I had to rename Main.swift to main.swift. Is there a design decision on why the filename for the main swift file has to be lowercase or is this a bug?

      If it's a design decision, why are directory names for source files allowed to have variations like Sources, Source, src and srcs as stated here but not the main swift file?

      I'd be ok if only Main.swift and main.swift are allowed since other files in the Sources directory are commonly UpperCamelCase due to the Type naming conventions e.g. example-package-playingcard/Sources.

      Or maybe I'm just being pedantic?

      p.s. even Package.swift is capitalized and not package.swift

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            contraultra nate
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated: