Просмотр исходного кода

Improve diagnostic for call to non-function. (#1245)

Richard Smith 4 лет назад
Родитель
Сommit
dbe535b719

+ 3 - 3
explorer/interpreter/type_checker.cpp

@@ -1131,9 +1131,9 @@ auto TypeChecker::TypeCheckExp(Nonnull<Expression*> e,
         }
         default: {
           return CompilationError(e->source_loc())
-                 << "in call, expected a function\n"
-                 << *e << "\nnot an operator of type "
-                 << call.function().static_type() << "\n";
+                 << "in call `" << *e
+                 << "`, expected callee to be a function, found `"
+                 << call.function().static_type() << "`";
         }
       }
       break;

+ 1 - 4
explorer/testdata/generic_class/fail_instantiate_non_generic.carbon

@@ -19,10 +19,7 @@ class Point {
 }
 
 fn Main() -> i32 {
-  // CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/generic_class/fail_instantiate_non_generic.carbon:[[@LINE+4]]: in call, expected a function
-  // CHECK: Point(i32)
-  // CHECK: not an operator of type typeof(class Point)
-  // CHECK-EMPTY:
+  // CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/generic_class/fail_instantiate_non_generic.carbon:[[@LINE+1]]: in call `Point(i32)`, expected callee to be a function, found `typeof(class Point)`
   var p: Point(i32) = Point.Origin();
   return 0;
 }

+ 1 - 4
explorer/testdata/generic_class/fail_self_with_arg.carbon

@@ -13,10 +13,7 @@ package ExplorerTest api;
 class Point(T:! Type) {
 
   // Error: wrote `Self(T)` instead of `Self`.
-  // CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/generic_class/fail_self_with_arg.carbon:[[@LINE+4]]: in call, expected a function
-  // CHECK: Self(T)
-  // CHECK: not an operator of type typeof(class Point(T = T:! Type))
-  // CHECK-EMPTY:
+  // CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/generic_class/fail_self_with_arg.carbon:[[@LINE+1]]: in call `Self(T)`, expected callee to be a function, found `typeof(class Point(T = T:! Type))`
   fn Origin(zero: T) -> Self(T) {
     return {.x = zero, .y = zero};
   }

+ 1 - 4
explorer/testdata/generic_class/fail_two_arg_lists.carbon

@@ -11,10 +11,7 @@
 package ExplorerTest api;
 
 class Point(T:! Type) {
-  // CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/generic_class/fail_two_arg_lists.carbon:[[@LINE+4]]: in call, expected a function
-  // CHECK: Point(T)(T)
-  // CHECK: not an operator of type typeof(class Point(T = T:! Type))
-  // CHECK-EMPTY:
+  // CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/generic_class/fail_two_arg_lists.carbon:[[@LINE+1]]: in call `Point(T)(T)`, expected callee to be a function, found `typeof(class Point(T = T:! Type))`
   fn Origin(zero: T) -> Point(T)(T) {
     return {.x = zero, .y = zero};
   }