diff --git a/dsymbol/src/dsymbol/ufcs.d b/dsymbol/src/dsymbol/ufcs.d index cd9a108..618c5a8 100644 --- a/dsymbol/src/dsymbol/ufcs.d +++ b/dsymbol/src/dsymbol/ufcs.d @@ -32,7 +32,7 @@ struct TokenCursorResult // https://dlang.org/spec/type.html#implicit-conversions enum string[string] INTEGER_PROMOTIONS = [ - "bool": "int", + "bool": "byte", "byte": "int", "ubyte": "int", "short": "int", @@ -40,6 +40,15 @@ enum string[string] INTEGER_PROMOTIONS = [ "char": "int", "wchar": "int", "dchar": "uint", + + // found in test case extra/tc_ufcs_all_kinds: + "int": "float", + "uint": "float", + "long": "float", + "ulong": "float", + + "float": "double", + "double": "real", ]; enum MAX_NUMBER_OF_MATCHING_RUNS = 50; @@ -273,10 +282,59 @@ private bool willImplicitBeUpcasted(scope ref const(DSymbol) incomingSymbolType, private bool typeWillBeUpcastedTo(string from, string to) { - if (auto promotionType = from in INTEGER_PROMOTIONS) - return *promotionType == to; + while (true) + { + if (typeWillIntegerUpcastedTo(from, to)) + return true; + if (from.typeIsFloating && to.typeIsFloating) + return true; - return false; + if (auto promotionType = from in INTEGER_PROMOTIONS) + { + if (*promotionType == to) + return true; + from = *promotionType; + } + else + return false; + } +} + +private bool typeWillIntegerUpcastedTo(string from, string to) +{ + int fromIntSize = getIntegerTypeSize(from); + int toIntSize = getIntegerTypeSize(to); + return fromIntSize != 0 && toIntSize != 0 && fromIntSize <= toIntSize; +} + +private int getIntegerTypeSize(string type) +{ + switch (type) + { + // ordered by subjective frequency of use, since the compiler may use that + // for optimization. + case "int", "uint": return 4; + case "long", "ulong": return 8; + case "byte", "ubyte": return 1; + case "short", "ushort": return 2; + case "dchar": return 4; + case "wchar": return 2; + case "char": return 1; + default: return 0; + } +} + +private bool typeIsFloating(string type) +{ + switch (type) + { + case "float": + case "double": + case "real": + return true; + default: + return false; + } } bool isNonConstrainedTemplate(scope ref const(DSymbol) symbolType) @@ -303,21 +361,24 @@ private bool typeMatchesWith(scope ref const(DSymbol) incomingSymbolType, scope return incomingSymbolType is significantSymbolType || isNonConstrainedTemplate(incomingSymbolType) || matchesWithTypeOfArray(incomingSymbolType, significantSymbolType) - || matchesWithTypeOfPointer(incomingSymbolType, significantSymbolType) - || willImplicitBeUpcasted(incomingSymbolType, significantSymbolType); + || matchesWithTypeOfPointer(incomingSymbolType, significantSymbolType); } -private bool matchSymbolType(const(DSymbol)* incomingSymbolType, const(DSymbol)* significantSymbolType) { +private bool matchSymbolType(const(DSymbol)* firstParameter, const(DSymbol)* significantSymbolType) { auto currentSignificantSymbolType = significantSymbolType; uint numberOfRetries = 0; do { - if (typeMatchesWith(*incomingSymbolType, *currentSignificantSymbolType)){ + if (typeMatchesWith(*firstParameter.type, *currentSignificantSymbolType)) { return true; } + if (!(firstParameter.parameterIsRef || firstParameter.parameterIsOut) + && willImplicitBeUpcasted(*firstParameter.type, *currentSignificantSymbolType)) + return true; + if (currentSignificantSymbolType.aliasThisSymbols.empty || currentSignificantSymbolType is currentSignificantSymbolType.aliasThisSymbols.front){ return false; } @@ -351,7 +412,7 @@ bool isCallableWithArg(const(DSymbol)* incomingSymbol, const(DSymbol)* beforeDot if (incomingSymbol.kind is CompletionKind.functionName && !incomingSymbol.functionParameters.empty && incomingSymbol.functionParameters.front.type) { - return matchSymbolType(incomingSymbol.functionParameters.front.type, beforeDotType); + return matchSymbolType(incomingSymbol.functionParameters.front, beforeDotType); } return false; } diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_bool_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_bool_test.txt index 36be1a9..d50d341 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_bool_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_bool_test.txt @@ -6,5 +6,18 @@ max k min k sizeof k someBool F +someByte F +someChar F +someDchar F +someDouble F +someFloat F someInt F +someLong F +someReal F +someShort F +someUbyte F +someUint F +someUlong F +someUshort F +someWchar F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_byte_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_byte_test.txt index 7e90a71..e20837b 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_byte_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_byte_test.txt @@ -6,5 +6,17 @@ max k min k sizeof k someByte F +someChar F +someDchar F +someDouble F +someFloat F someInt F +someLong F +someReal F +someShort F +someUbyte F +someUint F +someUlong F +someUshort F +someWchar F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_char_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_char_test.txt index 4cbcf1b..e20837b 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_char_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_char_test.txt @@ -5,6 +5,18 @@ mangleof k max k min k sizeof k +someByte F someChar F +someDchar F +someDouble F +someFloat F someInt F +someLong F +someReal F +someShort F +someUbyte F +someUint F +someUlong F +someUshort F +someWchar F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_dchar_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_dchar_test.txt index 4525617..3f23eb8 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_dchar_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_dchar_test.txt @@ -6,5 +6,11 @@ max k min k sizeof k someDchar F +someDouble F +someFloat F +someInt F +someLong F +someReal F someUint F +someUlong F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_double_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_double_test.txt index 6a84525..09d9ecc 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_double_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_double_test.txt @@ -15,4 +15,6 @@ min_normal k nan k sizeof k someDouble F +someFloat F +someReal F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_float_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_float_test.txt index 30d936a..09d9ecc 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_float_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_float_test.txt @@ -14,5 +14,7 @@ min_exp k min_normal k nan k sizeof k +someDouble F someFloat F +someReal F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_int_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_int_test.txt index 12183f9..3f23eb8 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_int_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_int_test.txt @@ -5,5 +5,12 @@ mangleof k max k min k sizeof k +someDchar F +someDouble F +someFloat F someInt F +someLong F +someReal F +someUint F +someUlong F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_long_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_long_test.txt index 90c08ce..e244de9 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_long_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_long_test.txt @@ -5,5 +5,9 @@ mangleof k max k min k sizeof k +someDouble F +someFloat F someLong F +someReal F +someUlong F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_real_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_real_test.txt index 21c83c4..09d9ecc 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_real_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_real_test.txt @@ -14,5 +14,7 @@ min_exp k min_normal k nan k sizeof k +someDouble F +someFloat F someReal F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_short_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_short_test.txt index 8f005e4..55047f4 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_short_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_short_test.txt @@ -5,6 +5,15 @@ mangleof k max k min k sizeof k +someDchar F +someDouble F +someFloat F someInt F +someLong F +someReal F someShort F +someUint F +someUlong F +someUshort F +someWchar F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_ubyte_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_ubyte_test.txt index e1d7fe6..e20837b 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_ubyte_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_ubyte_test.txt @@ -5,6 +5,18 @@ mangleof k max k min k sizeof k +someByte F +someChar F +someDchar F +someDouble F +someFloat F someInt F +someLong F +someReal F +someShort F someUbyte F +someUint F +someUlong F +someUshort F +someWchar F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_uint_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_uint_test.txt index b34ebf8..3f23eb8 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_uint_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_uint_test.txt @@ -5,5 +5,12 @@ mangleof k max k min k sizeof k +someDchar F +someDouble F +someFloat F +someInt F +someLong F +someReal F someUint F +someUlong F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_ulong_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_ulong_test.txt index 4d69bc6..e244de9 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_ulong_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_ulong_test.txt @@ -5,5 +5,9 @@ mangleof k max k min k sizeof k +someDouble F +someFloat F +someLong F +someReal F someUlong F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_ushort_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_ushort_test.txt index 1d75a22..55047f4 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_ushort_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_ushort_test.txt @@ -5,6 +5,15 @@ mangleof k max k min k sizeof k +someDchar F +someDouble F +someFloat F someInt F +someLong F +someReal F +someShort F +someUint F +someUlong F someUshort F +someWchar F stringof k diff --git a/tests/tc_ufcs_fundamental_types_completion/expected_wchar_test.txt b/tests/tc_ufcs_fundamental_types_completion/expected_wchar_test.txt index 7989ae3..55047f4 100644 --- a/tests/tc_ufcs_fundamental_types_completion/expected_wchar_test.txt +++ b/tests/tc_ufcs_fundamental_types_completion/expected_wchar_test.txt @@ -5,6 +5,15 @@ mangleof k max k min k sizeof k +someDchar F +someDouble F +someFloat F someInt F +someLong F +someReal F +someShort F +someUint F +someUlong F +someUshort F someWchar F stringof k