-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
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
__index cannot return a method #692
Comments
Hi, thanks for the report! It took me a bit of digging the back history to try to remember why Of course, in Lua, For example, want to be able to detect that the programmer made a typo and a method name is invalid, and that means that we need, at one point of the code, to declare that the declarations of methods are done. So you can only do Internally, Teal does keep track if a function "is a method" (that is, if it was declared with So, it's an explicit decision to not make Having said that, the problem you hit is that the current implementation of |
From: #692 > It took me a bit of digging the back history to try to remember why `.` and > `:` have separate handlers. Of course, in Lua, `:` is just syntactic sugar. In > Teal, however, we have in the language semantics separate concepts for > functions and record-functions/methods, because the latter are statically > bound to their records. > > For example, want to be able to detect that the programmer made a typo and a > method name is invalid, and that means that we need, at one point of the code, > to declare that the declarations of methods are done. So you can only do > `function my_record:mymethod` in the same scope where you created your record, > for instance. > > Internally, Teal does keep track if a function "is a method" (that is, if it > was declared with `:` or `.`; in more recent versions, we even check if a > function is method-like by having a first argument `self` with its own type). > This is to keep the door open for future enhancements to the type system, such > as interfaces (see this comment: > #97 (comment)). > > So, it's an explicit decision to not make `:` just a syntactic sugar for `.`, > like Lua.
From: #692 > It took me a bit of digging the back history to try to remember why `.` and > `:` have separate handlers. Of course, in Lua, `:` is just syntactic sugar. In > Teal, however, we have in the language semantics separate concepts for > functions and record-functions/methods, because the latter are statically > bound to their records. > > For example, want to be able to detect that the programmer made a typo and a > method name is invalid, and that means that we need, at one point of the code, > to declare that the declarations of methods are done. So you can only do > `function my_record:mymethod` in the same scope where you created your record, > for instance. > > Internally, Teal does keep track if a function "is a method" (that is, if it > was declared with `:` or `.`; in more recent versions, we even check if a > function is method-like by having a first argument `self` with its own type). > This is to keep the door open for future enhancements to the type system, such > as interfaces (see this comment: > #97 (comment)). > > So, it's an explicit decision to not make `:` just a syntactic sugar for `.`, > like Lua.
From: #692 > It took me a bit of digging the back history to try to remember why `.` and > `:` have separate handlers. Of course, in Lua, `:` is just syntactic sugar. In > Teal, however, we have in the language semantics separate concepts for > functions and record-functions/methods, because the latter are statically > bound to their records. > > For example, want to be able to detect that the programmer made a typo and a > method name is invalid, and that means that we need, at one point of the code, > to declare that the declarations of methods are done. So you can only do > `function my_record:mymethod` in the same scope where you created your record, > for instance. > > Internally, Teal does keep track if a function "is a method" (that is, if it > was declared with `:` or `.`; in more recent versions, we even check if a > function is method-like by having a first argument `self` with its own type). > This is to keep the door open for future enhancements to the type system, such > as interfaces (see this comment: > #97 (comment)). > > So, it's an explicit decision to not make `:` just a syntactic sugar for `.`, > like Lua.
From: #692 > It took me a bit of digging the back history to try to remember why `.` and > `:` have separate handlers. Of course, in Lua, `:` is just syntactic sugar. In > Teal, however, we have in the language semantics separate concepts for > functions and record-functions/methods, because the latter are statically > bound to their records. > > For example, want to be able to detect that the programmer made a typo and a > method name is invalid, and that means that we need, at one point of the code, > to declare that the declarations of methods are done. So you can only do > `function my_record:mymethod` in the same scope where you created your record, > for instance. > > Internally, Teal does keep track if a function "is a method" (that is, if it > was declared with `:` or `.`; in more recent versions, we even check if a > function is method-like by having a first argument `self` with its own type). > This is to keep the door open for future enhancements to the type system, such > as interfaces (see this comment: > #97 (comment)). > > So, it's an explicit decision to not make `:` just a syntactic sugar for `.`, > like Lua.
From: #692 > It took me a bit of digging the back history to try to remember why `.` and > `:` have separate handlers. Of course, in Lua, `:` is just syntactic sugar. In > Teal, however, we have in the language semantics separate concepts for > functions and record-functions/methods, because the latter are statically > bound to their records. > > For example, want to be able to detect that the programmer made a typo and a > method name is invalid, and that means that we need, at one point of the code, > to declare that the declarations of methods are done. So you can only do > `function my_record:mymethod` in the same scope where you created your record, > for instance. > > Internally, Teal does keep track if a function "is a method" (that is, if it > was declared with `:` or `.`; in more recent versions, we even check if a > function is method-like by having a first argument `self` with its own type). > This is to keep the door open for future enhancements to the type system, such > as interfaces (see this comment: > #97 (comment)). > > So, it's an explicit decision to not make `:` just a syntactic sugar for `.`, > like Lua.
Using
__index
to return a function ("."-style call) works, but returning a method (":"-style call does not)I’m not sure why the two are handled differently here and here. If I shunt the special
:
handling by addingor node.op.op == ":"
in the.
code (as shown bellow), this problem disappears, and the test suite still passes.The text was updated successfully, but these errors were encountered: