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

This commit is contained in:
Richard Smith
2022-05-10 16:06:15 -07:00
committed by GitHub
parent 0996b203fb
commit dbe535b719
4 changed files with 6 additions and 15 deletions
+3 -3
View File
@@ -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;
@@ -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
View File
@@ -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
View File
@@ -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};
}