-
Notifications
You must be signed in to change notification settings - Fork 16
Wollok v1.3 Confucius
We have changed the keyword that express class/WKO inheritance, instead of "extends" which has a broaden sense we now use inherits
class Dog inherits Animal {
// ...
}
You can have a catch block without specifying the type of the exception. In this case it will catch any wollok.lang.Exception (root class of all exceptions)
try {
a.m1()
}
catch e
console.println("blah")
We have done a very big refactor in the way Wollok implements "special" objects that comes with the language like booleans, strings, numbers, collections. Before v1.3.0 this where special object types that were part of the Wollok inner code. We have now modeled them in wollok language. They are part of the Wollok SDK library that is shipped automatically with Wollok language.
Here is a sample class diagram:
This means that all:
- You can now browse this classes for wollokdoc and for the implementation.
- other wollok mechanism like autocomplete or checks work for this basic objects
- Wollok Interpreter code is now more consistent.
Well-known objects can now inherit from classes which don't have a default constructor, and therefore require you to explicitly call a super constructor
A method can now declare that its last parameter is a vararg, which means that it can be called with a variable number of arguments, from 0 (zero) to "N".
Wollok will automatically wrap all those arguments in a list and call the method. So, from the method implementation point of view is just a list.
Here is a sample method declaration
Notices that it is a regular parameter followed with three dots. This are all valid calls
s.preffix("a", 1)
s.preffix("a", 1, 2)
s.preffix("a", 1, 2, 3)
s.preffix("a", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
We added several new static checks for errors and warnings that should really improve the experience working with Wollok. They should now catch errors sooner during coding instead of later in runtime with weird error messages and exceptions.
Similar to what the checker does to messages sent to "this", now it also validates messages to well-known objects (named objects, those defined with 'object x { ... }'
For some messages being sent Wollok can resolve them a particular methods. For the moment (without using the type system) those are:
- messages sent to this
- messages sent to super
- messages sent to well-known objects
In such a cases Wollok will now check if you are trying to use the return value of the message, and if it finds out that you are expecting a value but the method won't produce any value (doesn't have a return statement or uses the shorthand for methods returning a value) it will produce an error.
In this case "eat" doesn't return any valueThe checker now analyses the methods body and if they seems to be generating a value but the method is not returning it, it will raise a warning, since it is a common pitfall to forgot the return statement.
Now methods that have a return statement are analysed to make sure you are returning values on every possible flow.
The try catch with more than one catch blocks is now being checked to see if some of the catches are being hidden by a previous catch block
For example:
try {
a.m1()
assert.fail("Should have thrown exception")
}
catch e : AException
assert.fail("incorrect catch !")
catch e
console.println("blah")
// XPECT errors --> "Unreachable catch block" at "e"
catch e : BException
assert.fail("incorrect catch !")
Here BException catch is unreachable since BException is a subclass of AException
In order to make it fun working in Wollok for more advanced developers we have added new quick fixes for static checks, which should improve development experience and speed.
For the new check of messages to WKO we provide a quick fix to create a new method. It currently only works for objects defined in the same file.
In case you forgot it
We have made some majors improvements to the Wollok IDE (meaning the more visual concerns).
Now you can navigate certain messages to methods with CTRL+click or F3
For the moment this only works for messages being sent to:
- this
- super()
- well-known objects
Resolving any message will require to have a type system.
The content assist now got more clever. It will propose you real messages you can send to:
- this
- well-known objects
Example messages to this
Messages to WKO
In case you are sending a message to any other object besides this and a WKO, it will only shows you the list of messages you already sent to that variable within the context. Which is the best we can do without a type system.
If you are trying to send a message to a parameter, then we will analyse other methods of the current class/object and if we find a parameter with the same name, we will propose you the same messages as the ones you are sending on that other method.
Here is an example:
The REPL console now has syntax highlighting. This is useful to differentiate the input lines from the output given by the wollok REPL (interpreter). It also highlights errors, and tries to highlight the input code you write in a similar way as the text editor (keywords, strings, variables, etc)
Part of the highlighting is actually done at the REPL size, so if you run the REPL from a console you will still see colors. Although not the full highlight as you will see in the Eclipse. Here is a sample with a bash console
There's a new button on the REPL console which allow you to export the current session as a wollok test. It doesn't export the whole history (which is longer than the current session), just the lines you just wrote on this session.
Here is a sample generated test