diff --git a/examples/tests/invalid/super_call.w b/examples/tests/invalid/super_call.w index 74b175ca10a..72e8fee2a07 100644 --- a/examples/tests/invalid/super_call.w +++ b/examples/tests/invalid/super_call.w @@ -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) diff --git a/libs/wingc/src/type_check.rs b/libs/wingc/src/type_check.rs index 208644bd7f2..69a021331c5 100644 --- a/libs/wingc/src/type_check.rs +++ b/libs/wingc/src/type_check.rs @@ -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(), }) } diff --git a/tools/hangar/__snapshots__/invalid.ts.snap b/tools/hangar/__snapshots__/invalid.ts.snap index 99edd1f7a5e..472bd6c472a 100644 --- a/tools/hangar/__snapshots__/invalid.ts.snap +++ b/tools/hangar/__snapshots__/invalid.ts.snap @@ -1868,11 +1868,11 @@ 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 @@ -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