-
Notifications
You must be signed in to change notification settings - Fork 24
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
fix(compiler): Throw an error when comparing an alias and a named type with the same name [LNG-231] #946
Conversation
LNG-231 Fix NamedType creation with improper types
aqua:
compiles and produces air, but should not also it seems to crash aqua vscode extension |
): State[X, Boolean] = | ||
if (expected.acceptsValueOf(givenType)) State.pure(true) | ||
else { | ||
val expectedStr = alias.map(a => s"$a, that is an alias of '$expected'").getOrElse(expected.toString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val expectedStr = alias.map(a => s"$a, that is an alias of '$expected'").getOrElse(expected.toString) | |
val expectedStr = alias.map(a => s"$a (an alias of '$expected')").getOrElse(expected.toString) |
@@ -333,10 +333,12 @@ class TypesInterpreter[S[_], X](using | |||
override def ensureTypeMatches( | |||
token: Token[S], | |||
expected: Type, | |||
givenType: Type | |||
givenType: Type, | |||
alias: Option[String] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like adding this argument here. TypesAlgebra
is the one that should know about type aliases, it should not get this info from outside, should it?
Maybe lets add a separate method resolveNamedTypeConstruction
, which will take named type token and field types, then resolve the type and report a error if the type is not data
or ability
?
Remove |
@@ -58,6 +58,12 @@ class TypesInterpreter[S[_], X](using | |||
report.error(token, s"Unresolved type").as(None) | |||
} | |||
|
|||
def resolveNamedType(token: TypeToken[S]): State[X, Option[Type]] = | |||
resolveType(token).flatMap(_.flatTraverse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I believe we should move towards OptionT
because we have F[Option[A]]
almost all the time and it produces a lot of such flatMap(_.flatTraverse(
chains. But I am not insisting on rewriting this right now
@@ -58,6 +58,12 @@ class TypesInterpreter[S[_], X](using | |||
report.error(token, s"Unresolved type").as(None) | |||
} | |||
|
|||
def resolveNamedType(token: TypeToken[S]): State[X, Option[Type]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe result type is better to be NamedType
instead of Type
, or even AbilityType | StructType
, to avoid pattern matching on call site
Description
Throw compilation error on a code like this:
Implementation Details
Don't ignore named type comparison with aliases, improve type checking error.
Checklist
Reviewer Checklist