Questions tagged [void-safety]

Questions about compile-time techniques preventing calls on non-existing (void, also known as, null) targets in object-oriented languages. This includes usage of attachment annotations for types, problems with applying reattachment and access rules in void-safe code, issues with code patterns ensuring that particular expressions are attached to existing objects at run-time.

Background

Void-safety represents a sound static-analysis-based approach to guarantee that access on void target (causing null-pointer exceptions) may never occur at run-time in an object-oriented program that satisfies void-safety conditions. It is based on

  1. Type system that distinguishes between attached and detachable types. Attached types apply to variables and expressions that are always known to be attached to existing objects at run-time. Detachable types apply to variables and expressions that may be Void.

  2. Validity rules that allow for only

    • safe reattachments: An expression of a detachable type may be attached only to a variable of a detachable type, while an expression of an attached type may be attached to a variable of a type with arbitrary attachment status.
    • access on initialized variables: Before a variable may be accessed it has to be initialized. A variable of a detachable type may be initialized to Void (null), but a variable of an attached type has to be set to an existing or newly created object prior to its use.
  3. Certified attachment patterns (CAP): Code patterns that guarantee attachment status of expressions, for example

    ... -- x may be Void or attached to an object here, we do not know.
    if attached x then
            -- x is known to be attached here, so it is safe to make a call on it:
        x.foo
    end
    

Resources

Relation to other tags

  • - void-safety guarantees that expressions known to be of an attached type at compile-time always yield an exiting object at run-time
  • , - void-safety is a compile-time guarantee of absense of these exceptions in any execution scenario
14 questions
4
votes
2 answers

Is it OK to cast undefined to void in TS?

TLDR; Is this OK? Or is it bad practice? function isUndefined (payload: any): payload is undefined | void { return payload === undefined } Context In TypeScript, I have a function that can return either something or undefined or void. Something…
mesqueeb
  • 5,277
  • 5
  • 44
  • 77
3
votes
3 answers

Result attached or exception

Let's say that I have a function f which should return an attached T by calling g. However, g returns a detachable T. If g results in a Void, I want to raise an exception like this: f: T do if attached g as res then Result := res …
Ilgiz Mustafin
  • 414
  • 1
  • 4
  • 15
3
votes
1 answer

What's the point of the local variable in Eiffel's attached-statement?

In Eiffel, Void Safety is a way to statically prevent dereferencing uninitialised ("null") objects. The way it works is that first, the object has to be declared as detachable, and then you need to check in an if-block whether the object is actually…
Stazzney
  • 33
  • 2
2
votes
1 answer

Does Eiffel avoid ALL nulls?

I am actually using C# - but the question of Nulls came up on a local developers group (Chester Devs, UK) social site about the issues with nulls An object Person has a property, say Name, of type String If the name is not known then in C# Name is…
2
votes
1 answer

Class attributes in Eiffel

I am trying to make a class in Eiffel, consisting of a few attributes and functions. I keep getting issues with the attributes not being either visible to setName or not being initialised correctly. The compiler error is: VEVI: Variable is not…
cadebe
  • 651
  • 1
  • 12
  • 35
1
vote
1 answer

Address of an empty base optimized subobject

Let's say that I have a value: int i = 0; And an empty class eligible for being empty-base optimized: struct Empty{ // stuff that passes // static_assert( std::is_empty::value ); }; Is it legal to: Empty& e =…
1
vote
1 answer

Eiffel: compilation error `Source of assignment is not compatible with target`

With complete void check set in compiler I've got a Variable is not properly set compilation error on following case which for me is right (in my mind). It says that the source of assignment is not compatible with target. What am I missing here???…
Pipo
  • 4,653
  • 38
  • 47
0
votes
1 answer

How to display two generated ASCII text using inheritance in console application in C#

I'm trying to do a project with regard to displaying two separate text-animation in one line which shall display like this I am using inheritance for this. I, however, can't display them in one line. I need assistance aligning them in the same line…
0
votes
1 answer

Can someone explain to me how can i access a void* item that is inside a void** array, taking in account void** belongs to a struct

#include #include #include typedef struct student{ int grade; int enrollCode; }student; typedef struct colVoidStar{ int capacity; int num_itens_curr; void…
0
votes
2 answers

eiffel type conformance and attachement check not working

Trying to solve one of the SCOOP consequences with make_from_separate I'm running into an issue where at runtime types seem to be the same and won't pass the attached statement. non_separate_from_any non_separate_from_any, any_from_separate (v:…
Pipo
  • 4,653
  • 38
  • 47
0
votes
1 answer

variable is not properly set after renaming into heir

I know how to fix it (see my solution @bottom) but don't understand why this compilation error occurs, as in my mind, renamed attributes should be created by the Precursor into default_create. Why isn't that so? NRJ_ENTITY inherit ANY …
Pipo
  • 4,653
  • 38
  • 47
0
votes
1 answer

Eiffel: void safety, a concise way to test if an object exists and then call its feature

I was wondering if there is a clearer statement then if not attached foo then create foo end if attached foo as l_foo then l_foo.bark end as if not attached foo then create foo foo.bark else foo.bark end would repeat the…
Pipo
  • 4,653
  • 38
  • 47
0
votes
1 answer

Eiffel: Error: variable is not properly set. in make calling default_create or any parent calling/redefining default_create

Not sure exactly, but it makes various time I got a Error: variable is not properly set. in creation procedures' calling order. I figured out that creating class attributes before calling default_create seemed to solve the problem. Why is that so?…
Pipo
  • 4,653
  • 38
  • 47
0
votes
1 answer

Eiffel: Unknown identifier on attached check into require statement

require valid_item: attached item as l_i and then l_i.valid_for_insert or l_i.valid_for_update why do I have an unknown identifier here with l_i??!!!
Pipo
  • 4,653
  • 38
  • 47