Targeting / retention for a set of standard annotations, some inapplicable annotation checks replaced with target check, some fixed tests

This commit is contained in:
Mikhail Glukhikh
2015-07-16 11:35:28 +03:00
parent a75daf85e2
commit 94a00540be
53 changed files with 213 additions and 206 deletions
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.js.resolve
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.Visibilities
@@ -45,7 +46,11 @@ private abstract class AbstractNativeAnnotationsChecker(private val requiredAnno
val annotationDescriptor = descriptor.getAnnotations().findAnnotation(requiredAnnotation.fqName) ?: return
if (declaration !is JetNamedFunction || descriptor !is FunctionDescriptor) {
diagnosticHolder.report(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN.on(declaration, annotationDescriptor.getType()))
if (descriptor is FunctionDescriptor && descriptor !is ConstructorDescriptor) {
diagnosticHolder.report(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN.on(
declaration, annotationDescriptor.type)
)
}
return
}
+13
View File
@@ -16,21 +16,34 @@
package kotlin.js
import kotlin.annotation.AnnotationTarget.*
native
target(CLASSIFIER, FUNCTION, PROPERTY, CONSTRUCTOR, VALUE_PARAMETER)
public annotation class native(public val name: String = "")
native
target(FUNCTION)
public annotation class nativeGetter
native
target(FUNCTION)
public annotation class nativeSetter
native
target(FUNCTION)
public annotation class nativeInvoke
native
target(CLASSIFIER, FUNCTION, PROPERTY)
public annotation class library(public val name: String = "")
native
target(PROPERTY)
public annotation class enumerable()
// TODO make it "internal" or "fake"
native
target(CLASSIFIER)
deprecated("Do not use this annotation: it is for internal use only")
public annotation class marker
+2 -1
View File
@@ -17,4 +17,5 @@
package kotlin.jvm
// is used in common generated code in stdlib
internal annotation class jvmOverloads
target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR)
internal annotation(retention = AnnotationRetention.SOURCE) class jvmOverloads
+4 -2
View File
@@ -24,9 +24,11 @@ import kotlin.InlineOption.ONLY_LOCAL_RETURN
// They was reserved word in ECMAScript 2, but is not since ECMAScript 5.
native
public annotation class volatile
target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD)
public annotation(retention = AnnotationRetention.SOURCE) class volatile
native
public annotation class synchronized
target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
public annotation(retention = AnnotationRetention.SOURCE) class synchronized
public inline fun <R> synchronized(lock: Any, @inlineOptions(ONLY_LOCAL_RETURN) block: () -> R): R = block()
@@ -6,7 +6,7 @@ inline fun <T> doNothing1(a: T): T {
return a
}
inline fun <T> doNothing2(a: T, inline f: (T) -> T): T {
inline fun <T> doNothing2(a: T, f: (T) -> T): T {
return f(a)
}
+3 -3
View File
@@ -4,7 +4,7 @@ package foo
// CHECK_CONTAINS_NO_CALLS: testIf2
// CHECK_CONTAINS_NO_CALLS: testIf3
inline fun if1(inline f: (Int) -> Int, a: Int, b: Int, c: Int): Int {
inline fun if1(f: (Int) -> Int, a: Int, b: Int, c: Int): Int {
val result = f(a)
if (result == b) {
@@ -14,7 +14,7 @@ inline fun if1(inline f: (Int) -> Int, a: Int, b: Int, c: Int): Int {
return f(c)
}
inline fun if2(inline f: (Int) -> Int, a: Int, b: Int, c: Int): Int {
inline fun if2(f: (Int) -> Int, a: Int, b: Int, c: Int): Int {
if (f(a) == b) {
return f(a)
}
@@ -22,7 +22,7 @@ inline fun if2(inline f: (Int) -> Int, a: Int, b: Int, c: Int): Int {
return f(c)
}
inline fun if3(inline f: (Int) -> Int, a: Int, b: Int, c: Int): Int {
inline fun if3(f: (Int) -> Int, a: Int, b: Int, c: Int): Int {
if (f(a) == b) {
return f(a)
} else {
+2 -2
View File
@@ -9,11 +9,11 @@ class Inline {
return x
}
public inline fun <T> identity2 (x: T, inline f: (T) -> T): T {
public inline fun <T> identity2 (x: T, f: (T) -> T): T {
return f(x)
}
public inline fun <T> identity3 (inline f: () -> T): T {
public inline fun <T> identity3 (f: () -> T): T {
return f()
}
}
@@ -2,7 +2,7 @@ package foo
// CHECK_CONTAINS_NO_CALLS: sumEven
inline fun filteredReduce(a: Array<Int>, inline predicate: (Int) -> Boolean, inline reduceFun: (Int, Int) -> Int): Int {
inline fun filteredReduce(a: Array<Int>, predicate: (Int) -> Boolean, reduceFun: (Int, Int) -> Int): Int {
var result = 0
for (element in a) {
@@ -4,7 +4,7 @@ package foo
data class Result(var value: Int = 0, var invocationCount: Int = 0)
inline fun maxBy(a: Array<Int>, inline keyFun: (Int) -> Int): Int {
inline fun maxBy(a: Array<Int>, keyFun: (Int) -> Int): Int {
var maxVal = a[0]
var maxKey = keyFun(maxVal)
@@ -30,7 +30,7 @@ inline fun test3(state: State) {
}
}
noinline fun test(state: State) {
fun test(state: State) {
test3(state)
}
@@ -8,7 +8,7 @@ class State() {
public var value: Int = 0
}
noinline fun test(state: State) {
fun test(state: State) {
@inline fun test3() {
@inline fun test2() {
@inline fun test1() {
@@ -20,7 +20,7 @@ inline fun testInline(): Int {
return c
}
noinline fun testNoinline(): Int {
fun testNoinline(): Int {
return testInline()
}
@@ -17,7 +17,7 @@ inline fun testBreak(): Int {
return i
}
noinline fun testBreakNoinline() {
fun testBreakNoinline() {
assertEquals(4, testBreak(), "break")
}
@@ -33,7 +33,7 @@ inline fun testContinue(): Int {
return sum
}
noinline fun testContinueNoinline() {
fun testContinueNoinline() {
assertEquals(6, testContinue(), "continue")
}
@@ -6,7 +6,6 @@ fun <T> _enumerate(o: T): T = noImpl
native
fun _findFirst<T>(o: Any): T = noImpl
enumerable
class Test() {
val a: Int = 100
val b: String = "s"
@@ -6,7 +6,6 @@ package foo
class X
class Y
noinline
fun doRun<R>(fn: ()->R): R = fn()
inline fun test<reified A, reified B>(x: Any, y: Any): Boolean =