# Should the 5.0 branch currently report a language version of at least 5.0?

**URL:** <https://forums.swift.org/t/should-the-5-0-branch-currently-report-a-language-version-of-at-least-5-0/16857>\
**Category:** Compiler\
**Created:** [October 10, 2018, 4:05pm UTC](https://forums.swift.org/t/should-the-5-0-branch-currently-report-a-language-version-of-at-least-5-0/16857 "2018-10-10T16:05:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjhomer](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bjhomer/32/313_2.png) [@bjhomer](https://forums.swift.org/u/bjhomer)\
**Post date:** [October 10, 2018, 4:05pm UTC](https://forums.swift.org/t/should-the-5-0-branch-currently-report-a-language-version-of-at-least-5-0/16857/1 "2018-10-10T16:05:07Z")

</div>

I'm working on the implementation of a change that would go into Swift 5. It appears that the following check is failing:

```nohighlight
 if (cs.getTypeChecker().getLangOpts().isSwiftVersionAtLeast(5)) {
   // Do something
}

```

So it appears that the compiler does not believe that the Swift version is at least 5 on the `swift-5.0-branch`. Is that expected? Is there a better way to be checking for the Swift language version?

---

<div class="post-metadata">

**Author:** ![Alejandro](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alejandro/32/46197_2.png) [@Alejandro](https://forums.swift.org/u/Alejandro)\
**Post date:** [October 10, 2018, 4:28pm UTC](https://forums.swift.org/t/should-the-5-0-branch-currently-report-a-language-version-of-at-least-5-0/16857/2 "2018-10-10T16:28:30Z")

</div>

> <https://github.com/apple/swift/blob/swift-5.0-branch/CMakeLists.txt#L131>

The compiler has not yet been bumped to Swift 5 yet. The same is on master.

---

<div class="post-metadata">

**Author:** ![benrimmington](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/benrimmington/32/695_2.png) [@benrimmington](https://forums.swift.org/u/benrimmington)\
**Post date:** [October 10, 2018, 4:28pm UTC](https://forums.swift.org/t/should-the-5-0-branch-currently-report-a-language-version-of-at-least-5-0/16857/3 "2018-10-10T16:28:48Z")

</div>

[https://github.com/apple/swift/pull/18853](https://github.com/apple/swift/pull/18853)

---

<div class="post-metadata">

**Author:** ![hamishknight](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hamishknight/32/14226_2.png) [@hamishknight](https://forums.swift.org/u/hamishknight)\
**Post date:** [October 10, 2018, 4:37pm UTC](https://forums.swift.org/t/should-the-5-0-branch-currently-report-a-language-version-of-at-least-5-0/16857/4 "2018-10-10T16:37:37Z")

</div>

Note also that you're checking the effective language version, which takes into account compatibility mode versions. Therefore, passing the option `-swift-version 5` will allow the check to succeed even though the compiler version hasn't been bumped yet.

---

<div class="post-metadata">

**Author:** ![bjhomer](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bjhomer/32/313_2.png) [@bjhomer](https://forums.swift.org/u/bjhomer)\
**Post date:** [October 10, 2018, 4:39pm UTC](https://forums.swift.org/t/should-the-5-0-branch-currently-report-a-language-version-of-at-least-5-0/16857/5 "2018-10-10T16:39:40Z")

</div>

That's true. It does mean, however, that my tests are failing because I'm writing them under the expectation of Swift 5 behavior. Is there a better way to handle this? It seems like most of the SILGen tests, at least, are just operating on the latest standard version of Swift.

---

<div class="post-metadata">

**Author:** ![hamishknight](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hamishknight/32/14226_2.png) [@hamishknight](https://forums.swift.org/u/hamishknight)\
**Post date:** [October 10, 2018, 4:47pm UTC](https://forums.swift.org/t/should-the-5-0-branch-currently-report-a-language-version-of-at-least-5-0/16857/6 "2018-10-10T16:47:14Z")

</div>

Does passing `-swift-version 5` to your tests not solve the problem? e.g _(from [generic\_casts.swift](https://github.com/apple/swift/blob/43cfc33914e76f1b95760f1f2b148584c03224e1/test/SILGen/generic_casts.swift))_:

```
// RUN: %target-swift-emit-silgen -swift-version 5 -module-name generic_casts -Xllvm -sil-full-demangle -enable-sil-ownership %s | %FileCheck --check-prefix=CHECK --check-prefix=CHECK-%target-runtime %s

```

It's worth noting that currently [tests by default use `-swift-version 4`](https://github.com/apple/swift/blob/cdf986f3058a401244eccb582a69e3a711a8d6ee/test/lit.cfg#L322), so even if the compiler version were bumped, you would still need to pass `-swift-version 5` to test a Swift 5 mode specific change.

---

<div class="post-metadata">

**Author:** ![bjhomer](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bjhomer/32/313_2.png) [@bjhomer](https://forums.swift.org/u/bjhomer)\
**Post date:** [October 10, 2018, 6:40pm UTC](https://forums.swift.org/t/should-the-5-0-branch-currently-report-a-language-version-of-at-least-5-0/16857/7 "2018-10-10T18:40:31Z")

</div>

Ah, I see. I hadn't seen how to update the swift-version on a test-by-test basis. Thanks for pointing me in the right direction.

---

<div class="post-metadata">

**Author:** ![hamishknight](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hamishknight/32/14226_2.png) [@hamishknight](https://forums.swift.org/u/hamishknight)\
**Post date:** [October 10, 2018, 6:53pm UTC](https://forums.swift.org/t/should-the-5-0-branch-currently-report-a-language-version-of-at-least-5-0/16857/8 "2018-10-10T18:53:55Z")

</div>

No worries, sorry I should have provided an example (just edited to provide one that'll hopefully be of use to someone else).
