vrsperanza/CPY

don't decorate class constructors with "auto" keyword

okayzed opened this issue · 3 comments

I've been playing with CPY and one thing I noticed is that I don't have a way of writing class constructors / destructors when the auto inference is enabled.

#include <iostream>

class MyClass
    public:
    MyClass()
        ! "initializing"

    ~MyClass()
        ! "destructing"

    print_stuff()
        ! "printing stuff"

int main()

    MyClass c;

The above cpy code gets turned into the following. Notice that the constructor/destructor have had "auto" prepended to them, which is invalid C++ (they should have no return type).

#include <iostream>

class MyClass{
    public:;
    auto MyClass(){
        std::cout << "initializing" << std::endl;}

    auto ~MyClass(){
        std::cout << "destructing" << std::endl;}

    auto print_stuff(){
        std::cout << "printing stuff" << std::endl;}};

int main(){

    MyClass c;}

I'd like to discuss possible options for defining constructors that make sense in the context of .CPY.

  1. remember class names and if a function has the same name as a class, don't auto decorate it
  2. add special keyword to say "dont add anything to front of this line"
  3. add special constructor syntax or function names
  4. ???

Please let me know if any ideas make sense or which direction you are leaning.

I'm leaning in the direction of 1.
There's already an implementation of point 2 to avoid automatic declaration of variables
I will try to properly address this issue later today

I just implemented option 2, using the known keyword, same way it is done in order not to redeclare variables

I'd like to implement option 1, but I currently do not have the time, if you do it I'd gladly merge the project