Skip to content
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

Infix operator in compound expression crashes compiler #35

Closed
meijeru opened this issue May 15, 2011 · 5 comments
Closed

Infix operator in compound expression crashes compiler #35

meijeru opened this issue May 15, 2011 · 5 comments
Labels
status.tested The change in code has been manually tested and verified to fix the issue.

Comments

@meijeru
Copy link
Contributor

meijeru commented May 15, 2011

The following code

myand: func [[infix] a [integer!] b [integer!]][a and b]
17 myand 13 + 1

crashes the compiler with error:

** Script Error: size-of? expected type argument of type: word
** Where: set-width
** Near: width: emitter/size-of? either type [operand]
@dockimbel
Copy link
Member

This issue can be workaround by specifying a return value in 'myand definition. Currently the implementation requires that infix functions have a return type, I need to check the code to see if this dependency can be removed or if I need to add it to the specification draft.

@meijeru
Copy link
Contributor Author

meijeru commented May 16, 2011

That workaround has itself a problem: the infix function may be polymorphic! At least 'myand is, since it is a copy of 'and. Are you planning to allow more than one type in argument and return specs?

@meijeru meijeru closed this as completed May 16, 2011
@dockimbel dockimbel reopened this May 16, 2011
@dockimbel dockimbel reopened this May 16, 2011
@dockimbel
Copy link
Member

`myand' is part of an expression where it will be evaluated first (expressions are reduced from left to right reduction), so it requires parens on his right expression argument, else a compilation error will occur:

With parens:
17 myand (13 + 1), it is reduced to the prefix form: myand 17 + 13 1

Without parens:
17 myand 13 + 1, it is reduce to the prefix form: + myand 17 13 1

*** Compilation Error: return type missing in function: myand *** in: %tests/test.reds *** at: [myand 17 13 1 ]

@meijeru
Copy link
Contributor Author

meijeru commented May 18, 2011

I fail to see what is wrong with + myand 17 13 1 ! Since myand has two arguments, 17 and 13, it will yield an integer that can be added to 1 by +.

@dockimbel
Copy link
Member

It is not allowed to yield any value without a proper [return:] declaration in the function specification block. In my examples, in both cases, I have used your function declaration (so without any [return:] declaration).

In the "with parens" example, 'myand doesn't need to return anything as it is the root of the expression, so the compiler let it pass. In the "without parens" example, 'myand needs to return a value to be used as argument for '+ operator, in contradiction to 'myand specification block, so the compiler raises an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status.tested The change in code has been manually tested and verified to fix the issue.
Projects
None yet
Development

No branches or pull requests

2 participants