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

Default field values & default parameters #810

Merged

Conversation

knikamo
Copy link
Contributor

@knikamo knikamo commented May 30, 2017

We have implemented two new features, default field values and default parameters during our Independent Project in Information Engineering (similar to a bachelor thesis).

Default field values
Default field values are assignments added at the top of the init-method during desugaring. Default field values does not work for the main class since the init method is not called. Tobias suggested that he would solve this. There is currently no logic to prevent circular references or other unwanted expressions.

Default parameters
For each default parameter in a function/method declaration a new function/method is added during desugaring. During typechecking all function/method calls are adjusted to call the function/method with correct number of arguments. Default parameters work as expected according to the tests we have added.

General
We have not done anything with error handling or error messages. For example the error message for wrong number of arguments is now a bit weird since a function/method not always expects a fixed number of arguments.

We have written a few tests for each feature, but probably they do not cover everything.

@supercooldave
Copy link

Awesome to see this. Very useful features to have in Encore.

@@ -1412,7 +1433,7 @@ instance Checkable Expr where
tcError $ ValFieldAssignmentError name targetType
| otherwise = return ()


-- Karro

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is Karro?
If this is a comment, it could be removed.

@supercooldave
Copy link

There are a number of conflicts with the development branch of Encore. These need to be fixed before we can merge this PR. Do you need help doing that?

@kikofernandez
Copy link
Contributor

hi there! You should do a rebase instead of a merge. If you are unsure about how to do it, let us know. (I am going to check how to fix your conflicts and see if I can push a rebased version. Does this sound good?)

@knikamo
Copy link
Contributor Author

knikamo commented May 31, 2017

@kikofernandez aha okay it sounds good, I don't know how to do a rebase

returnWithEnd Field{fmeta, fmut, fname, ftype}
optional $ withLinebreaks $ reservedOp "="
fexpr <- optional expression
returnWithEnd Field{fmeta, fmut, fname, ftypr, fexpr}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this returnWithEnd Field{fmeta, fmut, fname, ftypr, fexpr} actually returnWithEnd Field{fmeta, fmut, fname, ftype, fexpr} (misspelling of ftypr to ftype)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes!

@kikofernandez
Copy link
Contributor

kikofernandez commented May 31, 2017

are you on the slack channel? There are some things that I need to explain and are probably not that relevant for the PR (otherwise send me an email to kiko.fernandez@it.uu.se and we continue some details that should be understood before I do this)

Copy link
Contributor

@kikofernandez kikofernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small number of improvements. Do not fix hem yet, as we are going to do the rebase and other stuff tomorrow.


nameForArg :: Int -> String
nameForArg 0 = ""
nameForArg x = show x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used. this can be removed

@@ -7,23 +7,107 @@ import AST.PrettyPrinter
import AST.Util
import Types
import Text.Megaparsec

import Data.Maybe
import Debug.Trace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be removed, this is only for debugging

@kikofernandez
Copy link
Contributor

there is a binary file that can be removed too

@knikamo
Copy link
Contributor Author

knikamo commented Jun 1, 2017

@kikofernandez helped us with a rebase and fixing the conflicts. The test for default field values in the main class fails, @EliasC is responsible to fix that.

Error messages are not adjusted to the new features. We are going to add issues about this after the PR is merged (right @EliasC ?)

@albertnetymk
Copy link
Contributor

There was a small discussion on cleaning up the commit history a bit before merging. If there's still some pending changes you would like to do, I think it could be nice to add them while revising the history.

@EliasC
Copy link
Contributor

EliasC commented Jun 1, 2017

The test for default field values in the main class fails, @EliasC is responsible to fix that.

I have this implemented locally now and I believe that it should work out of the box. Should I push the commit directly to this branch?

Error messages are not adjusted to the new features. We are going to add issues about this after the PR is merged (right @EliasC ?)

Yes please! The most important thing is that the known weaknesses are not forgotten. By creating an issue we increase the chances that someone is going to fix it at some point.

@kikofernandez
Copy link
Contributor

@EliasC I think you should push directly to the branch. I do not want to re-write the history until everything that needs to be fixed has been fixed.

@kikofernandez
Copy link
Contributor

kikofernandez commented Jun 1, 2017

Everyone: please let me know when everything is in place (issues have been created, all tests pass, etc) and I will do the interactive rebase to squash some commits together

@EliasC
Copy link
Contributor

EliasC commented Jun 1, 2017

I've pushed my addition to make the final test case pass. If CI passes, I'm happy with my addition and will not add anything else. @knikamo gets the final word on when everything is in place.

@EliasC
Copy link
Contributor

EliasC commented Jun 2, 2017

@knikamo: Can Kiko merge your commits and push it here? In other words, are you done and won't be adding anything else here?

@kikofernandez kikofernandez force-pushed the defFieldValues_defParams branch 2 times, most recently from aeee00e to 803118b Compare June 6, 2017 17:25
@kikofernandez
Copy link
Contributor

before merging, it would be good if I can get @casperstr and lowe's github email address, so that their commits are linked to their Github users. I'll wait until I get a confirmation on how to proceed

casperstr and others added 6 commits June 7, 2017 05:19
This commit has squashed the following commits into a single one

- removing pbcopy
- prepare for default values
- exprimenterar med seq väldigt nära nu
- default field parameters working with bugs
- do not desugar field without expression
- refactor. adding comments
- deacent looking
- adding basic test for default params
- moving to other class
- More tests
- testing expressions and adding out
- moving
- adding test for defaultParameters
- removing binary
- adding test for finalizer
- adding tests for multiple constructors
- myser lite
- funkar lite gran sådär
- chaning test
- working for functions
- testar lite
- got first part, (method decl) of default paramaters for methods
  working.  ie this.test1()
This commit has squashed the following commits:

- default params for methods fixed
- default params for function does not work
- default params for functions working
- added tests for default params
- string as default param in function fixed
- removed finalize- and multipleInits-tests
- default paramters for local functions fixed
- removed a comment
- added a test for object as default parameter
- edited test for object as default parameter
- added test for default field values in a class without an init method
- removed comment
- git fix
- default field values works for class without init
- removed files
- small fixes
This commit adds an implicit call to `init` at the beginning of
the `main` method. It also adds a restriction from defining a
constructor method in the `Main` class. "Why this madness?" I hear
you ask. This is to give field initialization a place to be
desugared into, while still keeping `main` as the starting point
of the program.
@kikofernandez
Copy link
Contributor

I believe this is ready for merge @EliasC

@kikofernandez
Copy link
Contributor

do not squash

@EliasC
Copy link
Contributor

EliasC commented Jun 7, 2017

👍 @kikofernandez

I am an author though, so you should press the button 😃

@kikofernandez kikofernandez merged commit 5cd60e4 into parapluu:development Jun 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants