We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Self
class Person { name: str friends: [Self...] constructor(self, name: str) { self.name = name self.friends = [] } fn add_friend(self, friend: Self) { self.friends.push(friend) } }
[ Trace ] INIT Virtual Stack at MODULE [00:00:00] Parsing (./bug.ms): Done in 211.1µs [ Debug ] pre-walk ".\\bug.ms" [ Debug ] registering new file ".\\bug.ms" (File { declarations: RefCell { value: [] }, location: ".\\bug.mmm", exports: RefCell { value: [] }, public_types: RefCell { value: {} }, compiled: CompilationLock(Cell { value: false }) }) -- Adding to: [] [ Trace ] Virtual Stack PUSH: Class <UNKNOWN> -> No [ Trace ] + name: str [00:00:00] Validating (./bug.ms): / [ Trace ] + friends: [Self...] [ Trace ] + name: str [ Debug ] ++ name used to have type str, but now it has type str [ Trace ] + friend: Self [ Trace ] + add_friend: fn(Self) [ Trace ] Virtual Stack POP [ Trace ] in scope Module, adding type Person = Person [ Info ] DONE preloading module .\bug.ms [ Info ] + mod "./bug.ms" ModuleType { exported_members: RefCell { value: [] }, public_types: RefCell { value: {} }, name: ".\\bug.ms" } [ Info ] + finished preload of ".\\bug.ms" [ Trace ] Virtual Stack PUSH: Class <UNKNOWN> -> No [ Trace ] + name: str [ Trace ] + friends: [Self...] [ Trace ] + name: str [ Debug ] ++ name used to have type str, but now it has type str [ Trace ] + friend: Self [ Trace ] + add_friend: fn(Self) [ Trace ] + Person: Person [ Trace ] class Person { ... } [ Trace ] + name: str [ Debug ] ++ name used to have type str, but now it has type str [ Trace ] + friends: [Self...] [ Debug ] ++ friends used to have type [Self...], but now it has type [Self...] [ Trace ] Virtual Stack PUSH: fn(???) -> Void [ Trace ] + self: Self [ Trace ] + name: str [ Debug ] lhs:Native(Str(StrWrapper(None))) rhs:Native(Str(StrWrapper(None))) f:TypecheckFlags { executing_class: Some(ClassType { name: "Person", path_str: ".\\bug.mmm", fields: [Ident { name: "name", ty: Some(Native(Str(StrWrapper(None)))), read_only: false }, Ident { name: "friends", ty: Some(List(Open(Class(<self referential class Person>)))), read_only: false }, Ident { name: "$constructor", ty: Some(Function(FunctionType { parameters: Named([Ident { name: "name", ty: Some(Native(Str(StrWrapper(None)))), read_only: false }]), return_type: RefCell { value: Void }, is_associated_fn: false, is_constructor: true })), read_only: true }, Ident { name: "add_friend", ty: Some(Function(FunctionType { parameters: Named([Ident { name: "friend", ty: Some(ClassSelf), read_only: false }]), return_type: RefCell { value: Void }, is_associated_fn: true, is_constructor: false })), read_only: false }] }), lhs_allow_optional_unwrap: true, force_rhs_to_be_unwrapped_lhs: false, signature_check: false, enforce_str_comptime_len_if_present: false } [ Debug ] lhs:List(Mixed([])) rhs:List(Open(Class(ClassType { name: "Person", path_str: ".\\bug.mmm", fields: [Ident { name: "name", ty: Some(Native(Str(StrWrapper(None)))), read_only: false }, Ident { name: "friends", ty: Some(List(Open(ClassSelf))), read_only: false }, Ident { name: "$constructor", ty: Some(Function(FunctionType { parameters: Named([Ident { name: "name", ty: Some(Native(Str(StrWrapper(None)))), read_only: false }]), return_type: RefCell { value: Void }, is_associated_fn: false, is_constructor: true })), read_only: true }, Ident { name: "add_friend", ty: Some(Function(FunctionType { parameters: Named([Ident { name: "friend", ty: Some(ClassSelf), read_only: false }]), return_type: RefCell { value: Void }, is_associated_fn: true, is_constructor: false })), read_only: false }] }))) f:TypecheckFlags { executing_class: Some(ClassType { name: "Person", path_str: ".\\bug.mmm", fields: [Ident { name: "name", ty: Some(Native(Str(StrWrapper(None)))), read_only: false }, Ident { name: "friends", ty: Some(List(Open(Class(<self referential class Person>)))), read_only: false }, Ident { name: "$constructor", ty: Some(Function(FunctionType { parameters: Named([Ident { name: "name", ty: Some(Native(Str(StrWrapper(None)))), read_only: false }]), return_type: RefCell { value: Void }, is_associated_fn: false, is_constructor: true })), read_only: true }, Ident { name: "add_friend", ty: Some(Function(FunctionType { parameters: Named([Ident { name: "friend", ty: Some(ClassSelf), read_only: false }]), return_type: RefCell { value: Void }, is_associated_fn: true, is_constructor: false })), read_only: false }] }), lhs_allow_optional_unwrap: true, force_rhs_to_be_unwrapped_lhs: false, signature_check: false, enforce_str_comptime_len_if_present: false } [ Trace ] Virtual Stack POP [ Trace ] Virtual Stack PUSH: fn(???) -> Void [ Trace ] + self: Self [ Trace ] + friend: Self [ Debug ] lhs:Class(ClassType { name: "Person", path_str: ".\\bug.mmm", fields: [Ident { name: "name", ty: Some(Native(Str(StrWrapper(None)))), read_only: false }, Ident { name: "friends", ty: Some(List(Open(ClassSelf))), read_only: false }, Ident { name: "$constructor", ty: Some(Function(FunctionType { parameters: Named([Ident { name: "name", ty: Some(Native(Str(StrWrapper(None)))), read_only: false }]), return_type: RefCell { value: Void }, is_associated_fn: false, is_constructor: true })), read_only: true }, Ident { name: "add_friend", ty: Some(Function(FunctionType { parameters: Named([Ident { name: "friend", ty: Some(ClassSelf), read_only: false }]), return_type: RefCell { value: Void }, is_associated_fn: true, is_constructor: false })), read_only: false }] }) rhs:ClassSelf f:TypecheckFlags { executing_class: None, lhs_allow_optional_unwrap: false, force_rhs_to_be_unwrapped_lhs: false, signature_check: false, enforce_str_comptime_len_if_present: false } [ Error ] ./bug.ms:11:21 > type mismatch when calling function (argument #1 was expected to be `Person` based on type signature, instead found `Self`) + hint: `Self` in this context means a function's associated class > "friend" [ Trace ] Virtual Stack POP [ Trace ] Virtual Stack POP [00:00:00] Validating (./bug.ms): !!! Error !!! --> ./bug.ms:11:21 | 11 | self.friends.push(friend) | ^----^ | = type mismatch when calling function (argument #1 was expected to be `Person` based on type signature, instead found `Self`) + hint: `Self` in this context means a function's associated class Error: Did not compile successfully (1 Error)
Allow this snippet, as Self does indeed refer to Person.
Not sure yet
The text was updated successfully, but these errors were encountered:
It appears as though ClassSelf is overly permissive (when calling a function) and allows instances of other classes as well.
ClassSelf
class A { fn foo(self, other: Self) { # ... } } class B { fn bar(self) { a = A() a.foo(self) # this line passes type checking, even though it shouldn't } }
Sorry, something went wrong.
fixed issues in #187
a0dd2e2
mrodz
Successfully merging a pull request may close this issue.
Snippet Responsible
Stack Trace of Error (--verbose, --no-pb)
Expected Behavior
Allow this snippet, as
Self
does indeed refer to Person.Any ideas where MScript breaks?
Brain Dump (Optional)
Not sure yet
The text was updated successfully, but these errors were encountered: