-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Disallow refinements in GivenTypes #6290
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
Conversation
Test case is i2567.scala. We would like to write ``` class Foo given T { ... } ``` But previously this mistook the class body as a refinement for `T`.
8c13610
to
9b1842d
Compare
I believe there might be something wrong with how given parameters are treated in tasty reflect.
I am not sure... Refinement types are allowed in the trait User
trait Order
trait TableName { type forEntity; val name: String }
object Instances {
implied userTbl for TableName {
type forEntity = User
val name = "user"
}
implied orderTbl for TableName {
type forEntity = Order
val name = "order"
}
}
object statements {
def select[T] given TableName { type forEntity = T } =
s"select * from ${the[TableName].name}"
}
import implied Instances._
println(statements.select[User ]) // select * from user
println(statements.select[Order]) // select * from order So not allowing them in the constructors brings inconsistency. This can invite the following pattern: // class Statements[T] given TableName { type forEntity = T } {
// def select = s"select * from ${the[TableName].name}"
// def selectWhere(where: String) = s"select * from ${the[TableName].name} where ${where}"
// }
class Statements[T](tn: TableName { type forEntity = T }) {
implied for TableName = tn
def select = s"select * from ${the[TableName].name}"
def selectWhere(where: String) = s"select * from ${the[TableName].name} where ${where}"
}
def Statements[T] given TableName { type forEntity = T } = new Statements[T](the[TableName])
import implied Instances._
println(Statements[User].selectWhere("id = 1")) One thing that comes to mind is to allow for an optional syntax for class definitions as follows: class Statements[T] given TableName { type forEntity = T } = {
/*...*/
} |
Good point. We could do one of two things:
def select[T] given (ev: TableName { type forEntity = T })
def select[T] given TableName { type forEntity = T } But that would make it inconsistent between def parameters and class parameters. My tendency would be to pick (1). |
Can we allow the following ? class Statements[T] given (TableName { type forEntity = T }) {
// ...
} |
Currently no. An opening |
Option 1 feels reasonable to me. Though the |
Test case is i2567.scala. We would like to write
But previously this mistook the class body as a refinement for
T
.