magik-tools-0.7.1-released

March 4, 2023    SonarQube static code analysis magik-language-server magik-debug-adapter

A new version of magik-tools was released. This release includes many changes regarding the type system, refactorings, as well as several fixes.

The biggest part of this release is the support for generics in the type system. Often used with collections, a generic allows you to specify the type of the objects part of the collection. For example, one can specify that the collection-type sw:rope holds objects of type sw:rwo_record. Each method which returns an element of sw:rope, for example sw:basic_collection_mixin.an_element() (inherited method), does not return an unknown type/type sw:object, but returns the specified type. Having the exact type, instead of sw:object, allows for better reasoning about the (type of the) variable.

To specify the type of a variable, a type annotation (override) should be used. For example:

_method object.m
	_local collection << sw:rope.new()  # type: sw:rope<sw:symbol>
	collection.add(:test)
	_local element << collection.an_element()  # <-- The type inferencer knows element is of type sw:symbol.
_endmethod

Or, to specify a slot of a slotted exemplar:

## Slot type example.
## @slot {sw:property_list<sw:symbol, sw:integer>} slot1
def_slotted_exemplar(
	:example,
	{
		{:slot1, _unset}
	})

This new functionality opens up the way to better refactoring, for example. Collections are used a lot in software. Knowing which type(s) the collection holds, it is easier to pinpoint where a given method is used.

Do note, however, that the type database does have to ‘know’ about the generics. The full list of changes can be found in the change log.