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

Newtype method option is not accessible under the test directory #278

Closed
valydia opened this issue Nov 14, 2024 · 2 comments
Closed

Newtype method option is not accessible under the test directory #278

valydia opened this issue Nov 14, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@valydia
Copy link

valydia commented Nov 14, 2024

Describe the bug

When I defined newtype with no constraint, I am not able to use the refinement method from the test directory

Environment

  • Scala: JVM
  • Scala version: 3.5.2
  • Iron version: 2.6.0

Reproduction steps

The structure of the project is as follows:

 >tree src
src
├── main
│   └── scala
│       ├── Main.scala
│       └── com
│           └── example
│               ├── Example.scala
│               └── mytypes.scala
└── test
    └── scala
        └── com
            └── example
                ├── Example.scala
                └── ExampleSpec.scala

Both Example.scala files are identical and here is their content:

package com.example

import mytypes.MyLong

object Example:

  def foo: Option[MyLong] = {
    val myLong = 3L
    MyLong.option(myLong)
  }

And here is mytypes content:

package com.example

import io.github.iltotore.iron.*

object mytypes {

  opaque type MyLong <: Long :| Pure = Long :| Pure
  object MyLong extends RefinedTypeOps.Transparent[MyLong]

}

Here is a link to a reproducible example

Expected behavior
Running the following command should allow the test to run successfully:

sbt test

Current behavior

When I run sbt test, the Example.scala file under test fails to compile with the following error:

[error] -- [E008] Not Found Error: /Users/valydia/Workspace/iron-not-working-in-test/src/test/scala/com/example/Example.scala:9:11 
[error] 9 |    MyLong.option(myLong)
[error]   |    ^^^^^^^^^^^^^
[error]   |value option is not a member of object com.example.mytypes.MyLong, but could be made available as an extension method.
[error]   |
[error]   |The following import might make progress towards fixing the problem:
[error]   |
[error]   |  import io.github.iltotore.iron.autoRefine
[error]   |
[error] one error found

Workaround

  1. If I copy the mytypes.scala file into the test directory, the tests run successfully.
  2. An even better one is to define MyLong as:
object MyLong extends RefinedTypeOps[Long, Pure, MyLong]
@valydia valydia added the bug Something isn't working label Nov 14, 2024
@Iltotore
Copy link
Owner

Hello!

The problem here is that you're using RefinedTypeOps.Transparent which is only for transparent (aka non-opaque) type aliases. Due to a compiler limitation, you have to use the more boilerplate-ish RefinedTypeOps[Long, Pure, MyLong].

FYI I'm working on a more concise newtipe definition in #253 for 3.0.0

@valydia
Copy link
Author

valydia commented Nov 19, 2024

Oh I see - I misunderstood - I thought somehow that RefinedTypeOps.Transparent was for New type with no constraint - Got it now - thanks for clarifying

@valydia valydia closed this as completed Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants