From bf4fef9a03fcb4ca2b1c36b9a4bcb0ac9679394c Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Sat, 12 Nov 2011 18:20:16 +0400 Subject: [PATCH] A non-generic function is always more speciic than a generic function Example: fun array(vararg array : T) = array fun array(vararg array : Char) = array fun test() { array('1', '2') // ambiguity } --- .../lang/resolve/calls/OverloadingConflictResolver.java | 1 + .../quick/GenericFunctionIsLessSpecific.jet | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 compiler/testData/checkerWithErrorTypes/quick/GenericFunctionIsLessSpecific.jet diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadingConflictResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadingConflictResolver.java index aa0f1c3ad95..2053006ceb2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadingConflictResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadingConflictResolver.java @@ -70,6 +70,7 @@ public class OverloadingConflictResolver { * Int < Short < Byte */ private boolean moreSpecific(Descriptor f, Descriptor g, boolean discriminateGenericDescriptors) { + if (discriminateGenericDescriptors && !isGeneric(f) && isGeneric(g)) return true; if (OverridingUtil.overrides(f, g)) return true; if (OverridingUtil.overrides(g, f)) return false; diff --git a/compiler/testData/checkerWithErrorTypes/quick/GenericFunctionIsLessSpecific.jet b/compiler/testData/checkerWithErrorTypes/quick/GenericFunctionIsLessSpecific.jet new file mode 100644 index 00000000000..308a3cd08c0 --- /dev/null +++ b/compiler/testData/checkerWithErrorTypes/quick/GenericFunctionIsLessSpecific.jet @@ -0,0 +1,8 @@ +// A generic funciton is always less specific than a non-generic one +fun foo(t : T) : Unit {} +fun foo(i : Int) : Int = 1 + +fun test() { + foo(1) : Int + foo("s") : Unit +} \ No newline at end of file