@@ -1021,7 +1021,7 @@ fn place_from_declarations_impl<'db>(
1021
1021
_ => Truthiness :: AlwaysFalse ,
1022
1022
} ;
1023
1023
1024
- let mut types = declarations. filter_map (
1024
+ let types = declarations. filter_map (
1025
1025
|DeclarationWithConstraint {
1026
1026
declaration,
1027
1027
reachability_constraint,
@@ -1045,14 +1045,45 @@ fn place_from_declarations_impl<'db>(
1045
1045
} ,
1046
1046
) ;
1047
1047
1048
- if let Some ( first) = types. next ( ) {
1048
+ let mut types = types. peekable ( ) ;
1049
+
1050
+ if types. peek ( ) . is_some ( ) {
1051
+ let mut union_elements = vec ! [ ] ;
1052
+ let mut queue = vec ! [ ] ;
1053
+
1054
+ for ty in types {
1055
+ match ty. inner_type ( ) {
1056
+ Type :: FunctionLiteral ( function) => {
1057
+ if function. literal ( db) . last_definition ( db) . is_overload ( db) {
1058
+ queue. push ( ty) ;
1059
+ } else {
1060
+ queue. clear ( ) ;
1061
+ union_elements. push ( ty) ;
1062
+ }
1063
+ }
1064
+ _ => {
1065
+ union_elements. append ( & mut queue) ;
1066
+
1067
+ union_elements. push ( ty) ;
1068
+ }
1069
+ }
1070
+ }
1071
+ union_elements. append ( & mut queue) ;
1072
+ // dbg!(&union_elements);
1073
+
1074
+ let mut union_elements = union_elements. into_iter ( ) ;
1075
+
1076
+ let first = union_elements
1077
+ . next ( )
1078
+ . expect ( "At least one type must be present" ) ;
1079
+
1049
1080
let mut conflicting: Vec < Type < ' db > > = vec ! [ ] ;
1050
- let declared = if let Some ( second) = types . next ( ) {
1081
+ let declared = if let Some ( second) = union_elements . next ( ) {
1051
1082
let ty_first = first. inner_type ( ) ;
1052
1083
let mut qualifiers = first. qualifiers ( ) ;
1053
1084
1054
1085
let mut builder = UnionBuilder :: new ( db) . add ( ty_first) ;
1055
- for other in std:: iter:: once ( second) . chain ( types ) {
1086
+ for other in std:: iter:: once ( second) . chain ( union_elements ) {
1056
1087
let other_ty = other. inner_type ( ) ;
1057
1088
if !ty_first. is_equivalent_to ( db, other_ty) {
1058
1089
conflicting. push ( other_ty) ;
0 commit comments