IDEA-109296 Resulting type of Date subtraction is incorrectly inferred as Integer

This commit is contained in:
Max Medvedev
2013-07-02 18:37:28 +04:00
parent f062a49f68
commit 612e89ba77
2 changed files with 44 additions and 1 deletions
@@ -284,8 +284,8 @@ public class ResolveUtil {
if (!psiClass.processDeclarations(processor, state, null, place)) return false;
}
}
if (!processNonCodeMembers(type, nonCodeProcessor, place, state)) return false;
if (!processCategoryMembers(place, nonCodeProcessor, state)) return false;
if (!processNonCodeMembers(type, nonCodeProcessor, place, state)) return false;
return true;
}
@@ -1593,4 +1593,47 @@ def foo() {
}
''', PsiMethod)
}
void testPreferCategoryMethods() {
def resolved = resolveByText('''
class TimeCategory {
public static TimeDuration minus(final Date lhs, final Date rhs) {
return new TimeDuration()
}
}
class TimeDuration {}
void bug() {
use (TimeCategory) {
def duration = new Date() - new Date()
print durat<caret>ion
}
}
''', GrVariable)
assertEquals("TimeDuration", resolved.typeGroovy.canonicalText)
}
void testPreferCategoryMethods2() {
def resolved = resolveByText('''
class TimeCategory {
public static TimeDuration minus(final Date lhs, final Date rhs) {
return new TimeDuration((int) days, hours, minutes, seconds, (int) milliseconds);
}
}
class TimeDuration {}
void bug() {
use (TimeCategory) {
def duration = new Date().minus(new Date())
print durat<caret>ion
}
}
''', GrVariable)
assertEquals("TimeDuration", resolved.typeGroovy.canonicalText)
}
}