Skip to content

Commit

Permalink
cr: err messages
Browse files Browse the repository at this point in the history
  • Loading branch information
yoav-steinberg committed Jul 20, 2023
1 parent 2779a94 commit 77c979b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/tests/invalid/super_call.w
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class B extends A {
static static_method() {
// super doesn't make sense in static context
super.method();
//^^^^^ Cannot call super method because we're not in an instance
//^^^^^ Cannot call super method inside of a static method
}
}

// super doesn't make sense in global context
super.do();
//^^ Cannot call super method because we're not in an instance
//^^ "super" can only be used inside of classes


// Verify correct error message when inflight closure tries to access super (this isn't suported yet see: https://github.com/winglang/wing/issues/3474)
Expand Down
7 changes: 6 additions & 1 deletion libs/wingc/src/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4304,7 +4304,12 @@ pub fn resolve_super_method(method: &Symbol, env: &SymbolEnv, types: &Types) ->
}
} else {
Err(TypeError {
message: "Cannot call super method because we're not in an instance".to_string(),
message: (if env.is_function {
"Cannot call super method inside of a static method"
} else {
"\"super\" can only be used inside of classes"
})
.to_string(),
span: method.span.clone(),
})
}
Expand Down
8 changes: 4 additions & 4 deletions tools/hangar/__snapshots__/invalid.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1868,11 +1868,11 @@ Duration <DURATION>"
`;
exports[`super_call.w 1`] = `
"error: Cannot call super method because we're not in an instance method (\\"super\\" is unknown in this context)
"error: \\"super\\" can only be used inside of classes
--> ../../../examples/tests/invalid/super_call.w:32:7
|
32 | super.do();
| ^^ Cannot call super method because we're not in an instance method (\\"super\\" is unknown in this context)
| ^^ \\"super\\" can only be used inside of classes
error: Cannot call super method because class A has no parent
Expand All @@ -1896,11 +1896,11 @@ error: super class \\"A\\" does not have a method named \\"child_method\\"
| ^^^^^^^^^^^^ super class \\"A\\" does not have a method named \\"child_method\\"
error: Cannot call super method because we're not in an instance method (\\"super\\" is unknown in this context)
error: Cannot call super method inside of a static method
--> ../../../examples/tests/invalid/super_call.w:26:11
|
26 | super.method();
| ^^^^^^ Cannot call super method because we're not in an instance method (\\"super\\" is unknown in this context)
| ^^^^^^ Cannot call super method inside of a static method
error: \`super\` calls inside inflight closures not supported yet, see: https://github.com/winglang/wing/issues/3474
Expand Down

0 comments on commit 77c979b

Please sign in to comment.