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

Update solutions for type inference exercises in the compendium #769

Open
johannesnydahl opened this issue Nov 3, 2023 · 2 comments
Open

Comments

@johannesnydahl
Copy link
Contributor

There seems to be some solutions to type inference exercises that are incorrect in the current version of the compendium, presumably due to more precise type inference in newer Scala compiler versions for union types.

I recall finding a few of these errors in the past, but this is the only one I have noted down (Exercise 2C, W08):

image

The solution says:

image

However, when trying this myself using Scala REPL the compiler infer more precise types than Any and AnyVal:
image

I personally think that solutions to exercises like these have to be revised in order to not confuse students. Maybe we can include both the general and the precise type?

@bjornregnell
Copy link
Member

bjornregnell commented Nov 4, 2023

Thanks for reporting.

Yes, with union types in Scala 3 the type inference is more precise now and all the types shown in repl sessions in answers to exercises should be inspected to see if they have changed from Scala 2 to Scala 3.

PR:s are welcome.

@bjornregnell
Copy link
Member

Thanks for PR @axelnilsson98
I guess there are more places where there could be more precise type in in Appendix Lösningar? so I'll keep this issue open until a search for Any and Matchable has been conducted and re-run in repl to see what we get in Scala >=3.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants