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

[Feature] Implement high-level typeof operator #663

Closed
7 tasks done
Tracked by #688 ...
lorenzholzbauer opened this issue Jul 16, 2024 · 1 comment · Fixed by #688
Closed
7 tasks done
Tracked by #688 ...

[Feature] Implement high-level typeof operator #663

lorenzholzbauer opened this issue Jul 16, 2024 · 1 comment · Fixed by #688
Assignees
Labels
feature New feature or enhancement
Milestone

Comments

@lorenzholzbauer
Copy link
Member

lorenzholzbauer commented Jul 16, 2024

Is there an existing proposal for this?

  • I have searched the existing issues

This feature does not exist in the latest version

  • I am using the latest version

Proposal

Add a typeof operator that returns the runtime object instead of a string like in JS.

For example:

  • Null:
    var x: null = null;
    
    var y: type = typeof x; // -> null
  • Primitives:
    var x: str = "x";
    
    var y: type = typeof x; // -> str
  • Objects:
    interface X {
      prop: num
    }
    
    var x: X = {
      prop: 1
    };
    
    var y: type = typeof x; // -> obj  
  • Arrays:
    var x: Array<num> = [1, 2, 3]
    
    var y: type = typeof x; // -> Array  
  • Functions:
    var x: Func<num> = (): num -> {
      return 1;
    };
    
    var y: type = typeof x; // -> Func<num>
  • Class:
    class Duck {
      ...
    }
    
    var x = new Duck();
    var y: type = typeof x; // -> Duck

Exact behaviour / changes you want

  • [Feature] Add runtime type generation for builtin types #659
  • Add typeof operator which is a built-in keyword that is separate from any references and such.
  • Add internal code structure required to evaluate the type of a variable at runtime.
  • Add type information to functions so they can also be used with typeof.
  • Add internal function typeof implementing the functionality for typeof.
@lorenzholzbauer lorenzholzbauer added feature New feature or enhancement question Further information is requested labels Jul 16, 2024
@lorenzholzbauer lorenzholzbauer changed the title [Feature] HIgh Level Typeof Operator [Feature] High Level Typeof Operator Jul 16, 2024
@Luna-Klatzer Luna-Klatzer changed the title [Feature] High Level Typeof Operator [Feature] High Level typeof operator Jul 18, 2024
@Luna-Klatzer Luna-Klatzer removed the question Further information is requested label Jul 18, 2024
@Luna-Klatzer Luna-Klatzer changed the title [Feature] High Level typeof operator [Feature] Implement high-level typeof operator Jul 18, 2024
@Luna-Klatzer Luna-Klatzer added this to the v0.12.0 milestone Jul 18, 2024
lorenzholzbauer added a commit that referenced this issue Jul 26, 2024
@Luna-Klatzer
Copy link
Member

Implemented by #688

@Luna-Klatzer Luna-Klatzer mentioned this issue Sep 7, 2024
11 tasks
@Luna-Klatzer Luna-Klatzer mentioned this issue Sep 18, 2024
39 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or enhancement
Projects
2 participants