Binary and unary expression support

This commit is contained in:
Mikhael Bogdanov
2013-12-02 16:05:51 +04:00
parent 431e61ef74
commit 621a4002e4
16 changed files with 426 additions and 55 deletions
@@ -0,0 +1,14 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
inline fun inlineFunWithInvoke(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) {
var d = <!USAGE_IS_NOT_INLINABLE!>s<!>
d = <!USAGE_IS_NOT_INLINABLE!>s<!>
var e = <!USAGE_IS_NOT_INLINABLE!>ext<!>
e = <!USAGE_IS_NOT_INLINABLE!>ext<!>
}
inline fun Function1<Int, Unit>.inlineExt() {
var d = <!USAGE_IS_NOT_INLINABLE!>this<!>
d = <!USAGE_IS_NOT_INLINABLE!>this<!>
}
@@ -0,0 +1,27 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
inline fun <T, U> Function1<T, U>.get(index : Int) {
}
inline fun <T, U, V> ExtensionFunction1<T, U, V>.get(index : Int) {
}
inline fun <T, U, V> inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) {
s[1]
ext[1]
}
//noinline
fun <T, U, V> Function2<T, U, V>.get(index : Int) {
}
fun <T, U, V, W> ExtensionFunction2<T, U, V, W>.get(index : Int) {
}
inline fun <T, U, V, W> inlineFunWithInvoke(s: (p: T, l: U) -> V, ext: T.(p: U, l: V) -> W) {
<!USAGE_IS_NOT_INLINABLE!>s<!>[1]
<!USAGE_IS_NOT_INLINABLE!>ext<!>[1]
}
@@ -0,0 +1,30 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
fun <T, U> Function1<T, U>.minusAssign(p: Function1<T, U>) {}
inline fun <T, U> Function1<T, U>.modAssign(p: Function1<T, U>) = {
this += p
p += this
}
inline fun <T, U> Function1<T, U>.plusAssign(p: Function1<T, U>) {
<!USAGE_IS_NOT_INLINABLE!>this<!> -= <!USAGE_IS_NOT_INLINABLE!>p<!>
<!USAGE_IS_NOT_INLINABLE!>p<!> -= <!USAGE_IS_NOT_INLINABLE!>this<!>
}
fun <T, U, V> ExtensionFunction1<T, U, V>.minusAssign(ext : ExtensionFunction1<T, U, V>) {}
inline fun <T, U, V> ExtensionFunction1<T, U, V>.modAssign(ext : ExtensionFunction1<T, U, V>) = {
this += ext
ext += this
}
inline fun <T, U, V> ExtensionFunction1<T, U, V>.plusAssign(ext : ExtensionFunction1<T, U, V>) {
<!USAGE_IS_NOT_INLINABLE!>this<!> -= <!USAGE_IS_NOT_INLINABLE!>ext<!>
<!USAGE_IS_NOT_INLINABLE!>ext<!> -= <!USAGE_IS_NOT_INLINABLE!>this<!>
}
inline fun <T, U, V> inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) {
s += s
ext += ext
}
@@ -0,0 +1,32 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
inline fun <T, U> Function1<T, U>.compareTo(p: Function1<T, U>) = 1
inline fun <T, U, V> ExtensionFunction1<T, U, V>.compareTo(index : ExtensionFunction1<T, U, V>) = 1
inline fun <T, U, V> inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) {
s < s
s <= s
s > s
s >= s
ext < ext
ext > ext
ext <= ext
ext >= ext
}
//noinline
fun <T, U, V> Function2<T, U, V>.compareTo(index : Function2<T, U, V>) = 1
fun <T, U, V, W> ExtensionFunction2<T, U, V, W>.compareTo(index : ExtensionFunction2<T, U, V, W>) = 1
inline fun <T, U, V, W> inlineFunWithInvoke(s: (p: T, l: U) -> V, ext: T.(p: U, l: V) -> W) {
<!USAGE_IS_NOT_INLINABLE!>s<!> < <!USAGE_IS_NOT_INLINABLE!>s<!>
<!USAGE_IS_NOT_INLINABLE!>s<!> <= <!USAGE_IS_NOT_INLINABLE!>s<!>
<!USAGE_IS_NOT_INLINABLE!>s<!> > <!USAGE_IS_NOT_INLINABLE!>s<!>
<!USAGE_IS_NOT_INLINABLE!>s<!> >= <!USAGE_IS_NOT_INLINABLE!>s<!>
<!USAGE_IS_NOT_INLINABLE!>ext<!> < <!USAGE_IS_NOT_INLINABLE!>ext<!>
<!USAGE_IS_NOT_INLINABLE!>ext<!> > <!USAGE_IS_NOT_INLINABLE!>ext<!>
<!USAGE_IS_NOT_INLINABLE!>ext<!> <= <!USAGE_IS_NOT_INLINABLE!>ext<!>
<!USAGE_IS_NOT_INLINABLE!>ext<!> >= <!USAGE_IS_NOT_INLINABLE!>ext<!>
}
@@ -0,0 +1,22 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
inline fun <T, U> Function1<T, U>.component1() = 1
inline fun <T, U> Function1<T, U>.component2() = 2
inline fun <T, U, V> ExtensionFunction1<T, U, V>.component1() = 1
inline fun <T, U, V> ExtensionFunction1<T, U, V>.component2() = 2
inline fun <T, U, V> inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) {
val (d1, e1) = s
val (d2, e2) = ext
}
fun <T, U, V> Function2<T, U, V>.component1() = 1
fun <T, U, V> Function2<T, U, V>.component2() = 2
fun <T, U, V, W> ExtensionFunction2<T, U, V, W>.component1() = 1
fun <T, U, V, W> ExtensionFunction2<T, U, V, W>.component2() = 2
inline fun <T, U, V, W> inlineFunWithInvoke(s: (p: T, l: U) -> V, ext: T.(p: U, l: V) -> W) {
val (d1, e1) = <!USAGE_IS_NOT_INLINABLE, USAGE_IS_NOT_INLINABLE!>s<!>
val (d2, e2) = <!USAGE_IS_NOT_INLINABLE, USAGE_IS_NOT_INLINABLE!>ext<!>
}
@@ -0,0 +1,34 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
inline fun <T, U> Function1<T, U>.contains(p: Function1<T, U>): Boolean {
this in p
p in this
return false
}
inline fun <T, U, V> ExtensionFunction1<T, U, V>.contains(ext: ExtensionFunction1<T, U, V>): Boolean {
ext in this
this in ext
return false
}
inline fun <T, U, V> inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) {
s in s
s !in s
ext in ext
ext !in ext
}
fun <T, U, V> Function2<T, U, V>.contains(p: Function2<T, U, V>): Boolean = false
fun <T, U, V, W> ExtensionFunction2<T, U, V, W>.contains(ext: ExtensionFunction2<T, U, V, W>): Boolean = false
inline fun <T, U, V> inlineFunWithInvoke(s: (p: T, l: U) -> U, ext: T.(p: U, l: U) -> V) {
<!USAGE_IS_NOT_INLINABLE!>s<!> in <!USAGE_IS_NOT_INLINABLE!>s<!>
<!USAGE_IS_NOT_INLINABLE!>s<!> !in <!USAGE_IS_NOT_INLINABLE!>s<!>
<!USAGE_IS_NOT_INLINABLE!>ext<!> in <!USAGE_IS_NOT_INLINABLE!>ext<!>
<!USAGE_IS_NOT_INLINABLE!>ext<!> !in <!USAGE_IS_NOT_INLINABLE!>ext<!>
}
@@ -0,0 +1,34 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
fun <T, U> Function1<T, U>.minus(p: Function1<T, U>) {
}
fun <T, U, V> ExtensionFunction1<T, U, V>.minus(p: T.(p: U) -> V) {
}
inline fun <T, U> Function1<T, U>.plus(p: Function1<T, U>) {
<!USAGE_IS_NOT_INLINABLE!>this<!> - <!USAGE_IS_NOT_INLINABLE!>p<!>
}
inline fun <T, U, V> ExtensionFunction1<T, U, V>.plus(p: T.(p: U) -> V) {
<!USAGE_IS_NOT_INLINABLE!>this<!> - <!USAGE_IS_NOT_INLINABLE!>p<!>
}
inline fun <T, U, V> inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) {
s + s
ext + ext
}
inline fun <T, U, V> inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) {
s + s
ext + ext
}
inline fun <T, U> Function1<T, U>.submit() {
this + this
}
inline fun <T, U, V> ExtensionFunction1<T, U, V>.submit() {
this + this
}
@@ -0,0 +1,39 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
inline fun <T, U> Function1<T, U>.rangeTo(p: Function1<T, U>): Range<Int> {
this..p
p..this
return 1..2
}
inline fun <T, U, V> ExtensionFunction1<T, U, V>.rangeTo(ext: ExtensionFunction1<T, U, V>): Range<Int> {
ext..this
this..ext
return 1..2
}
inline fun <T, U, V> inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) {
s..s
s..s
ext..ext
ext..ext
}
fun <T, U, V> Function2<T, U, V>.rangeTo(p: Function2<T, U, V>): Range<Int> {
return 1..2
}
fun <T, U, V, W> ExtensionFunction2<T, U, V, W>.rangeTo(ext: ExtensionFunction2<T, U, V, W>): Range<Int> {
return 1..2
}
inline fun <T, U, V> inlineFunWithInvoke(s: (p: T, l: U) -> U, ext: T.(p: U, l: U) -> V) {
<!USAGE_IS_NOT_INLINABLE!>s<!>..<!USAGE_IS_NOT_INLINABLE!>s<!>
<!USAGE_IS_NOT_INLINABLE!>s<!>..<!USAGE_IS_NOT_INLINABLE!>s<!>
<!USAGE_IS_NOT_INLINABLE!>ext<!>..<!USAGE_IS_NOT_INLINABLE!>ext<!>
<!USAGE_IS_NOT_INLINABLE!>ext<!>..<!USAGE_IS_NOT_INLINABLE!>ext<!>
}
@@ -0,0 +1,16 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNNECESSARY_SAFE_CALL -UNNECESSARY_NOT_NULL_ASSERTION
inline fun String.submit(action: Function1<Int, Int>) {
}
inline fun Function1<Int, Int>.submit() {
<!USAGE_IS_NOT_INLINABLE!>this<!>?.invoke(11)
<!USAGE_IS_NOT_INLINABLE!>this<!>!!.invoke(11)
submit(<!USAGE_IS_NOT_INLINABLE!>this<!>!!)
}
inline fun submit(action: Function1<Int, Int>) {
<!USAGE_IS_NOT_INLINABLE!>action<!>?.invoke(10)
<!USAGE_IS_NOT_INLINABLE!>action<!>!!.invoke(10)
}
@@ -0,0 +1,35 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -VAL_REASSIGNMENT -UNUSED_CHANGED_VALUE -VARIABLE_EXPECTED
inline fun <T, V> Function1<T, V>.plus() = <!USAGE_IS_NOT_INLINABLE!>this<!>
fun <T, V> Function1<T, V>.minus() = this
inline fun <T, V> Function1<T, V>.inc() = <!USAGE_IS_NOT_INLINABLE!>this<!>
fun <T, V> Function1<T, V>.dec() = this
inline fun <T, V> ExtensionFunction1<T, T, V>.plus(){}
fun <T, V> ExtensionFunction1<T, T, V>.minus(){}
inline fun <T, V> ExtensionFunction1<T, T, V>.inc() = <!USAGE_IS_NOT_INLINABLE!>this<!>
fun <T, V> ExtensionFunction1<T, T, V>.dec() = this
inline fun <T, V> inlineFunWithInvoke(s: (p: T) -> V, ext: T.(p: T) -> V) {
+s
-<!USAGE_IS_NOT_INLINABLE!>s<!>
s++
++s
<!USAGE_IS_NOT_INLINABLE!>s<!>--
--<!USAGE_IS_NOT_INLINABLE!>s<!>
+ext
-<!USAGE_IS_NOT_INLINABLE!>ext<!>
ext++
++ext
<!USAGE_IS_NOT_INLINABLE!>ext<!>--
--<!USAGE_IS_NOT_INLINABLE!>ext<!>
}
inline fun <T, V> Function1<T, V>.inlineFunWithInvoke() {
+this
-<!USAGE_IS_NOT_INLINABLE!>this<!>
this++
++this
<!USAGE_IS_NOT_INLINABLE!>this<!>--
--<!USAGE_IS_NOT_INLINABLE!>this<!>
}
@@ -0,0 +1,26 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
inline fun <T, V> Function1<T, V>.not() : Boolean {
return !this
}
inline fun <T, V> ExtensionFunction1<T, T, V>.not() : Boolean {
return !this
}
inline fun <T, V> inlineFunWithInvoke(s: (p: T) -> V, ext: T.(p: T) -> V) {
!s
!ext
}
fun <T, U, V> Function2<T, U, V>.not() : Boolean {
return !this
}
fun <T, U, V, W> ExtensionFunction2<T, U, V, W>.not() : Boolean {
return !this
}
inline fun <T, U, V> inlineFunWithInvoke(s: (p: T, l: U) -> V, ext: T.(p: T, l : U) -> V) {
!<!USAGE_IS_NOT_INLINABLE!>s<!>
!<!USAGE_IS_NOT_INLINABLE!>ext<!>
}
@@ -1,12 +1,11 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -NOTHING_TO_INLINE -USELESS_ELVIS
inline fun inlineFunWrongUsage(s: (p: Int) -> Unit) {
<!USAGE_IS_NOT_INLINABLE!>s<!>
if (true) <!USAGE_IS_NOT_INLINABLE!>s<!> else 0
var c = <!USAGE_IS_NOT_INLINABLE!>s<!>
c = <!USAGE_IS_NOT_INLINABLE!>s<!>
<!USAGE_IS_NOT_INLINABLE!>s<!> ?: <!USAGE_IS_NOT_INLINABLE!>s<!>
}
inline fun inlineFunWrongUsageExt(ext: Int.(p: Int) -> Unit) {
@@ -14,8 +13,7 @@ inline fun inlineFunWrongUsageExt(ext: Int.(p: Int) -> Unit) {
if (true) <!USAGE_IS_NOT_INLINABLE!>ext<!> else 0
var c = <!USAGE_IS_NOT_INLINABLE!>ext<!>
c = <!USAGE_IS_NOT_INLINABLE!>ext<!>
<!USAGE_IS_NOT_INLINABLE!>ext<!> ?: <!USAGE_IS_NOT_INLINABLE!>ext<!>
}
inline fun inlineFunWrongUsageInClosure(s: (p: Int) -> Unit) {
@@ -24,8 +22,7 @@ inline fun inlineFunWrongUsageInClosure(s: (p: Int) -> Unit) {
if (true) <!USAGE_IS_NOT_INLINABLE!>s<!> else 0
var c = <!USAGE_IS_NOT_INLINABLE!>s<!>
c = <!USAGE_IS_NOT_INLINABLE!>s<!>
<!USAGE_IS_NOT_INLINABLE!>s<!> ?: <!USAGE_IS_NOT_INLINABLE!>s<!>
}()
}
@@ -35,21 +32,20 @@ inline fun inlineFunWrongUsageInClosureExt(ext: Int.(p: Int) -> Unit) {
if (true) <!USAGE_IS_NOT_INLINABLE!>ext<!> else 0
var c = <!USAGE_IS_NOT_INLINABLE!>ext<!>
c = <!USAGE_IS_NOT_INLINABLE!>ext<!>
<!USAGE_IS_NOT_INLINABLE!>ext<!> ?: <!USAGE_IS_NOT_INLINABLE!>ext<!>
}()
}
inline fun inlineFunNoInline(noinline s: (p: Int) -> Unit) {
s
if (true) s else 0
var c = s
c = s
s ?: s
}
inline fun inlineFunNoInline(noinline ext: Int.(p: Int) -> Unit) {
ext
if (true) ext else 0
var c = ext
c = ext
}
ext ?: ext
}
@@ -1,24 +0,0 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -UNNECESSARY_SAFE_CALL -UNNECESSARY_NOT_NULL_ASSERTION
public inline fun assertNot(message: String, block: ()-> Boolean) {}
public inline fun assertNot(block: ()-> Boolean) : Unit = assertNot(<!USAGE_IS_NOT_INLINABLE!>block<!>.toString(), block)
public fun <T> callable(action: ()-> T) {
}
public inline fun <T> String.submit(action: ()->T) {
callable(<!USAGE_IS_NOT_INLINABLE!>action<!>)
}
public inline fun <T> Function1<Int, Int>.submit() {
<!USAGE_IS_NOT_INLINABLE!>this<!>?.invoke(11)
<!USAGE_IS_NOT_INLINABLE, USAGE_IS_NOT_INLINABLE!>this<!>!!.invoke(11)
}
public inline fun <T> submit(action: Function1<Int, Int>) {
<!USAGE_IS_NOT_INLINABLE!>action<!>?.invoke(10)
<!USAGE_IS_NOT_INLINABLE, USAGE_IS_NOT_INLINABLE!>action<!>!!.invoke(10)
}