Skip to content

Commit

Permalink
Add @static3
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Dec 20, 2023
1 parent c458f0d commit 1f6fd88
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ package object annotation {
type nowarn213 = nowarnIgnored
type nowarn3 = nowarnIgnored

type static3 = staticIgnored

type targetName3 = targetNameIgnored

type threadUnsafe3 = threadUnsafeIgnored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ package object annotation {
type nowarn213 = nowarn
type nowarn3 = nowarnIgnored

type static3 = staticIgnored

type targetName3 = targetNameIgnored

type threadUnsafe3 = threadUnsafeIgnored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ package object annotation {
type nowarn213 = nowarnIgnored
type nowarn3 = nowarn

type static3 = scala.annotation.static

type targetName3 = scala.annotation.targetName

type threadUnsafe3 = scala.annotation.threadUnsafe
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2022 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.typelevel.scalaccompat.annotation
package internal

private[annotation] class staticIgnored extends scala.annotation.Annotation
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2022 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.typelevel.scalaccompat.annotation

object CustomStaticHelper {
final val isScala3 = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2022 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.typelevel.scalaccompat.annotation

object CustomStaticHelper {
final val isScala3 = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2022 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.typelevel.scalaccompat.annotation

import munit.FunSuite

class CustomStaticDemo
object CustomStaticDemo {
@static3 val foo = 42
}

class CustomStaticSuite extends FunSuite {

test("static3 respected on Scala 3 only") {
val fields = classOf[CustomStaticDemo].getFields().map(_.getName).toList

if (CustomStaticHelper.isScala3) {
assertEquals(fields, List("foo"))
} else { // Scala 2
assertEquals(fields, Nil)
}
}

}

0 comments on commit 1f6fd88

Please sign in to comment.