Scala 2.11 refined with scalatest MustMatchers and Await causes compiler error "trying to do lub/glb of typevar ?F[?T, ?B]" - scalatest

I have been trying to use the refined with scalatest and am getting compiler errors at the "typer" phase: trying to do lub/glb of typevar ?F[?T, ?B]
This is my best attempt at a minimalist reproduction of the issue using a self-contained ammonite script:
import $ivy.`eu.timepit::refined:0.9.0`
import $ivy.`org.scalatestplus.play::scalatestplus-play:3.1.2`
import org.scalatest.{MustMatchers, WordSpec}
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import eu.timepit.refined.auto.autoInfer
class RefinedSpec extends WordSpec with MustMatchers {
val duration = 500.millis
val fut = Future.successful("123")
Await.result(fut, atMost = duration)
}
If you make any one of the following changes to the above it will successfully compile:
delete: import eu.timepit.refined.auto.autoInfer
remove: with MustMatchers from the class definition
delete: Await.result(fut, atMost = duration)
To clarify, this is a compilation error, not a runtime error. The original error is happening in a play app (scala 2.11.11) whilst running test:compile in sbt, but it's probably easier to reproduce it with the ammonite script.
The ammonite version I'm using gives version info:
Welcome to the Ammonite Repl 1.1.2
(Scala 2.11.12 Java 1.8.0_25)
Installed using:
sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/lihaoyi/Ammonite/releases/download/1.1.2/2.11-1.1.2) > /usr/local/bin/amm && chmod +x /usr/local/bin/amm' && amm
More error details from the ammonite example:
scala.reflect.internal.FatalError:
trying to do lub/glb of typevar ?F[?T, ?B]
while compiling: fail.sc
during phase: typer
library version: version 2.11.12
compiler version: version 2.11.12
reconstructed args: -nowarn -Yresolve-term-conflict:object
last tree to typer: Ident(<argument>)
tree position: line 15 of fail.sc
tree tpe: String
symbol: <none>
symbol definition: <none> (a NoSymbol)
symbol package: <none>
symbol owners:
call site: class RefinedSpec in object fail in package $file
From play sbt test:compile I also get this kind of output:
[error] last tree to typer: Ident(<argument>)
[error] tree position: line 13 of ...../RefinedSpec.scala
[error] tree tpe: String
[error] symbol: <none>
[error] symbol definition: <none> (a NoSymbol)
[error] symbol package: <none>
[error] symbol owners:
[error] call site: class RefinedSpec in package foo in package foo
[error]
[error] == Source file context for tree position ==
[error]
[error] 10 val duration = 500.millis
[error] 11 val fut = Future.successful("123")
[error] 12 Await.result(fut, atMost = duration)
[error] 13 }
This isn't a serious issue as I can just remove the autoInfer import as I'm not actually using it. It will trip people up though because they'll tend to do:
import eu.timepit.refined.auto._
to get automatic conversion from compile-time constants into refined types, when they can probably just get away with:
import eu.timepit.refined.auto.autoRefineV

Related

Quill imports results in "missing dependencies" error

We're attempting to upgrade to angular 11 and are finding that Quill.import results in errors:
An error occurred during the build:
Error: The target entry-point "#project/project-pattern-lib" has missing dependencies:
- core/module
- blots/block/embed
- modules/clipboard
- delta
- formats/link
at TargetedEntryPointFinder.findEntryPoints (D:\Dev\Git_project\project\node_modules\#angular\compiler-cli\ngcc\src\entry_point_finder\targeted_entry_point_finder.js:40:23)
at D:\Dev\Git_project\project\node_modules\#angular\compiler-cli\ngcc\src\execution\analyze_entry_points.js:29:41
r.js:28:29)
at SyncLocker.lock (D:\Dev\Git_project\project\node_modules\#angular\compiler-cli\ngcc\src\locking\sync_locker.js:34:24)
at SingleProcessExecutorSync.execute (D:\Dev\Git_project\project\node_modules\#angular\compiler-cli\ngcc\src\execution\single_process_executor.js:57:27)
at Object.mainNgcc (D:\Dev\Git_project\project\node_modules\#angular\compiler-cli\ngcc\src\main.js:74:25)
at Object.process (D:\Dev\Git_project\project\node_modules\#angular\compiler-cli\ngcc\index.js:29:23)
at NgccProcessor.processModule (D:\Dev\Git_project\project\node_modules\#ngtools\webpack\src\ngcc_processor.js:163:16)
at D:\Dev\Git_project\project\node_modules\#ngtools\webpack\src\ivy\host.js:109:18
at D:\Dev\Git_project\project\node_modules\#ngtools\webpack\src\ivy\host.js:39:24
at Array.map (<anonymous>)
at Object.host.resolveModuleNames (D:\Dev\Git_project\project\node_modules\#ngtools\webpack\src\ivy\host.js:37:32)
at actualResolveModuleNamesWorker (D:\Dev\Git_project\project\node_modules\typescript\lib\typescript.js:102904:133)
at resolveModuleNamesWorker (D:\Dev\Git_project\project\node_modules\typescript\lib\typescript.js:103126:26)
at resolveModuleNamesReusingOldState (D:\Dev\Git_project\project\node_modules\typescript\lib\typescript.js:103200:24)
- core/module
- blots/block/embed
- modules/clipboard
- delta
- formats/link
See "C:\Users\Name\AppData\Local\Temp\ng-nIGMuY\angular-errors.log" for further details.
We can't seem to find anything in terms of a fix out there. All of these "missing dependencies" are referenced in the code like:
import Quill from "quill";
const BlockEmbed = Quill.import(
"blots/block/embed"
) as typeof Parchment.default.Embed;
Figured out there is a weird syntax issue here and the following solves it:
const blockPath = 'blots/block/embed';
const BlockEmbed = Quill.import(blockPath);
Don't know why this fixes it.

Gatling compilation fails for simulation with nothingFor function

I am trying to run simulation with nothingFor function under Gatling 3.4.1. However, compilation fails with the error could not find implicit value for evidence parameter of type io.gatling.core.controller.inject.InjectionProfileFactory[Product with Serializable]
Simulation
package abs
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class DefaultSimulation extends Simulation {
...
val httpProtocol = http
.baseUrl(Setting.baseUrl)
.userAgentHeader("Gatling/3.4.1")
setUp(
getScenario.inject(
nothingFor(20 seconds),
rampConcurrentUsers(0) to(20) during(10 seconds),
constantConcurrentUsers(20) during (600 seconds)
),
setScenario.inject(
rampConcurrentUsers(0) to(20) during(30 seconds),
constantConcurrentUsers(20) during (600 seconds)
)
).protocols(httpProtocol)
}
Compilation error
[ERROR] i.g.c.ZincCompiler$ - C:/Installation/gatling-3.4.1/user-files/simulations/DefaultSimulation.scala:50:30: could not find implicit value for evidence parameter of type io.gatling.core.controller.inject.InjectionProfileFactory[Product with Serializable]
getScenario.inject(
^
[ERROR] i.g.c.ZincCompiler$ - one error found
[ERROR] i.g.c.ZincCompiler$ - Compilation crashed
xsbt.InterfaceCompileFailed: null
at xsbt.CachedCompiler0.handleErrors(CompilerBridge.scala:183)
at xsbt.CachedCompiler0.run(CompilerBridge.scala:172)
at xsbt.CachedCompiler0.run(CompilerBridge.scala:134)
at xsbt.CompilerBridge.run(CompilerBridge.scala:39)
at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:89)
at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:185)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:240)
at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:175)
at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:156)
at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:232)
at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:156)
at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:203)
at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:571)
at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:571)
at sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:174)
at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:172)
at sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:459)
at sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:115)
at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:248)
at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:414)
at sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:499)
at sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:401)
at sbt.internal.inc.Incremental$.apply(Incremental.scala:166)
at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:571)
at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:489)
at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:419)
at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
at io.gatling.compiler.ZincCompiler$.doCompile(ZincCompiler.scala:258)
at io.gatling.compiler.ZincCompiler$.delayedEndpoint$io$gatling$compiler$ZincCompiler$1(ZincCompiler.scala:265)
at io.gatling.compiler.ZincCompiler$delayedInit$body.apply(ZincCompiler.scala:40)
at scala.Function0.apply$mcV$sp(Function0.scala:39)
at scala.Function0.apply$mcV$sp$(Function0.scala:39)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1$adapted(App.scala:80)
at scala.collection.immutable.List.foreach(List.scala:431)
at scala.App.main(App.scala:80)
at scala.App.main$(App.scala:78)
at io.gatling.compiler.ZincCompiler$.main(ZincCompiler.scala:40)
at io.gatling.compiler.ZincCompiler.main(ZincCompiler.scala)
I have tried to implicitly specify imports, but compilation fails with the same exception
import io.gatling.core.Predef.{nothingFor, rampConcurrentUsers, constantConcurrentUsers, _}
This simulation compiles and works without nothingFor(20 seconds).
Gatling has 2 different families of injection profiles steps:
open, where you control users arrival rate
closed where you control the number of concurrent users
You can't mix them because those are 2 completely different and incompatible behaviors.
nothingFor belongs to the open family while rampConcurrentUsers belongs to the closed one.
Use constantConcurrentUsers(0) during (20) instead.

In gatling, I got an error with "Exception in thread "main" java.lang.ExceptionInInitializerError"

When I run Engine.scala under the scala directory,it gives an error:
Exception in thread "main" java.lang.ExceptionInInitializerError
at Engine$.delayedEndpoint$Engine$1(Engine.scala:7)
at Engine$delayedInit$body.apply(Engine.scala:4)
at scala.Function0.apply$mcV$sp(Function0.scala:34)
at scala.Function0.apply$mcV$sp$(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App.$anonfun$main$1$adapted(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:389)
at scala.App.main(App.scala:76)
at scala.App.main$(App.scala:74)
at Engine$.main(Engine.scala:4)
at Engine.main(Engine.scala)
Caused by: java.lang.NullPointerException
at io.gatling.commons.util.PathHelper$.url2path(PathHelper.scala:34)
at IDEPathHelper$.<init>(IDEPathHelper.scala:7)
at IDEPathHelper$.<clinit>(IDEPathHelper.scala)
... 11 more
And BaiduHomePageSimulation.scala is:
package test.scala
import io.gatling.core.Predef._
import io.gatling.http.Predef._
class BaiduSimulation extends Simulation {
// Set the root path of the request
val httpConf = http.baseUrl("https://www.baidu.com")
/*
run 10 seconds, during:the default unit is seconds, if you want to use microseconds eg. during(100 millisecond)
*/
val scn = scenario("BaiduSimulation").during(10){
exec(http("baidu_home").get("/"))
}
// set the thread count
setUp(scn.inject(atOnceUsers(10)).protocols(httpConf))
}
I don't konw how to fix it? Has anyone encountered a similar issue?
I was getting this error and was able to resolve it by marking the scala directory as Test Sources Root
Right click scala folder > Mark directory as > Test Sources Root

React native with haul not working, throwing some loader issue

I have added haul to my react native project to analyze why my release build fails. but I got another problem instead. I have a webpack.haul.js with following config
module.exports = {
entry: './index.js',
};
When i run react-native run-android i see the following error. Can someone help me please.
ERROR Failed to compile.
./node_modules/native-base-shoutem-theme/src/StyleProvider.js 10:19
Module parse failed: Unexpected token (10:19)
You may need an appropriate loader to handle this file type.
| */
| export default class StyleProvider extends React.Component {
> static propTypes = {
| children: PropTypes.element.isRequired,
| style: PropTypes.object,
# ./node_modules/native-base-shoutem-theme/index.js 3:0-48 7:0-15:2
# ./node_modules/native-base/dist/src/index.js
# ./screens/Academics/HomeWorkScreen.js
# ./App.js
# ./index.js
# multi ./node_modules/haul/src/vendor/polyfills/Object.es6.js ./node_modules/haul/src/vendor/polyfills/console.js ./node_modules/haul/src/vendor/polyfills/error-guard.js ./node_modules/haul/src/vendor/polyfills/Number.es6.js ./node_modules/haul/src/vendor/polyfills/String.prototype.es6.js ./node_modules/haul/src/vendor/polyfills/Array.prototype.es6.js ./node_modules/haul/src/vendor/polyfills/Array.es6.js ./node_modules/haul/src/vendor/polyfills/Object.es7.js ./node_modules/haul/src/vendor/polyfills/babelHelpers.js ./node_modules/react-native/Libraries/Core/InitializeCore.js ./node_modules/haul/src/utils/polyfillEnvironment.js ./index.js
./node_modules/native-base-shoutem-theme/src/connectStyle.js 116:26
Module parse failed: Unexpected token (116:26)
You may need an appropriate loader to handle this file type.
|
| class StyledComponent extends React.Component {
> static contextTypes = {
| theme: ThemeShape,
| // The style inherited from the parent
# ./node_modules/native-base-shoutem-theme/index.js 1:0-46 7:0-15:2
# ./node_modules/native-base/dist/src/index.js
# ./screens/Academics/HomeWorkScreen.js
# ./App.js
# ./index.js
# multi ./node_modules/haul/src/vendor/polyfills/Object.es6.js ./node_modules/haul/src/vendor/polyfills/console.js ./node_modules/haul/src/vendor/polyfills/error-guard.js ./node_modules/haul/src/vendor/polyfills/Number.es6.js ./node_modules/haul/src/vendor/polyfills/String.prototype.es6.js ./node_modules/haul/src/vendor/polyfills/Array.prototype.es6.js ./node_modules/haul/src/vendor/polyfills/Array.es6.js ./node_modules/haul/src/vendor/polyfills/Object.es7.js ./node_modules/haul/src/vendor/polyfills/babelHelpers.js ./node_modules/react-native/Libraries/Core/InitializeCore.js ./node_modules/haul/src/utils/polyfillEnvironment.js ./index.js
./node_modules/rn-fetch-blob/index.js 13:12
Module parse failed: Unexpected token (13:12)
You may need an appropriate loader to handle this file type.
| AppState,
| } from 'react-native'
> import type {
| RNFetchBlobNative,
| RNFetchBlobConfig,
# ./screens/Academics/HomeWorkScreen.js 1:603-627
# ./App.js
# ./index.js
# multi ./node_modules/haul/src/vendor/polyfills/Object.es6.js ./node_modules/haul/src/vendor/polyfills/console.js ./node_modules/haul/src/vendor/polyfills/error-guard.js ./node_modules/haul/src/vendor/polyfills/Number.es6.js ./node_modules/haul/src/vendor/polyfills/String.prototype.es6.js ./node_modules/haul/src/vendor/polyfills/Array.prototype.es6.js ./node_modules/haul/src/vendor/polyfills/Array.es6.js ./node_modules/haul/src/vendor/polyfills/Object.es7.js ./node_modules/haul/src/vendor/polyfills/babelHelpers.js ./node_modules/react-native/Libraries/Core/InitializeCore.js ./node_modules/haul/src/utils/polyfillEnvironment.js ./index.js
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:bundleDemshReleaseJsAndAssets'.
> Process 'command 'node'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Your problem is that somehow or other, babel is not configured correctly to compile the features that exist in the code mentioned in those errors.
The specific problems:
static method properties (you need https://babeljs.io/docs/en/babel-plugin-proposal-class-properties)
flow types (you need https://babeljs.io/docs/en/babel-plugin-transform-flow-strip-types)
It's hard to say exactly what is wrong with your config, but a faster way to test is to run the babel CLI directly on those files. If you ensure that BABEL_ENV and any other babel cli/env/API flags are set the same way as they are in the webpack build (you might have to do some debugging to find where babel-loader is applied), you can do for example yarn run babel node_modules/native-base-shoutem-theme/src/StyleProvider.js
If you can reproduce the problem like this, you can experiment in a much tigher loop with your babel configuration until you find a solution.
A good starting points is updating babel and all the presets/plugins you have installed.

package com.google.android.gms.iid does not exist import com.google.android.gms.iid.InstanceID

Am trying to include GCM as native bundle. This runs as a background service but i cant get the build to compile successfully. I have android.playService.gcm=true as build hint. But i get the folliwng errors. It seems nothing in com.google.android.gms is being picked up. I have also enabled gradle build.
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RixmaInstanceIDListenerService.java:15: error: package com.google.android.gms.iid does not exist
import com.google.android.gms.iid.InstanceID;
^
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RixmaInstanceIDListenerService.java:16: error: package com.google.android.gms.iid does not exist
import com.google.android.gms.iid.InstanceIDListenerService;
^
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RixmaInstanceIDListenerService.java:18: error: cannot find symbol
public class RixmaInstanceIDListenerService extends InstanceIDListenerService {
^
symbol: class InstanceIDListenerService
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RegistrationIntentService.java:15: error: cannot find symbol
import com.google.android.gms.gcm.GcmPubSub;
^
symbol: class GcmPubSub
location: package com.google.android.gms.gcm
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RegistrationIntentService.java:17: error: package com.google.android.gms.iid does not exist
import com.google.android.gms.iid.InstanceID;
^
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RixmaGcmListenerService.java:20: error: cannot find symbol
import com.google.android.gms.gcm.GcmListenerService;
^
symbol: class GcmListenerService
location: package com.google.android.gms.gcm
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RixmaGcmListenerService.java:22: error: cannot find symbol
public class RixmaGcmListenerService extends GcmListenerService {
^
symbol: class GcmListenerService
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RixmaInstanceIDListenerService.java:34: error: cannot find symbol
startService(intent);
^
symbol: method startService(Intent)
location: class RixmaInstanceIDListenerService
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RixmaInstanceIDListenerService.java:28: error: method does not override or implement a method from a supertype
#Override
^
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RegistrationIntentService.java:40: error: cannot find symbol
InstanceID instanceID = InstanceID.getInstance(this);
^
symbol: class InstanceID
location: class RegistrationIntentService
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RegistrationIntentService.java:40: error: cannot find symbol
InstanceID instanceID = InstanceID.getInstance(this);
^
symbol: variable InstanceID
location: class RegistrationIntentService
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RegistrationIntentService.java:42: error: cannot find symbol
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
^
symbol: variable INSTANCE_ID_SCOPE
location: class GoogleCloudMessaging
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RegistrationIntentService.java:83: error: cannot find symbol
GcmPubSub pubSub = GcmPubSub.getInstance(this);
^
symbol: class GcmPubSub
location: class RegistrationIntentService
/tmp/build6570310071572581493xxx/RixmaM/src/main/java/com/rixma/mobile/RegistrationIntentService.java:83: error: cannot find symbol
GcmPubSub pubSub = GcmPubSub.getInstance(this);
^
symbol: variable GcmPubSub
location: class RegistrationIntentService
Please point me where i might be going wrong.
Many thanks
The old flag uses play services version 6.5.* the above were introduced on version 7.5 if I'm not mistaken
We temporarily disabled the Gradle build functionality as covered here.
There were just too many regressions, so for now it should be back to the old gplay services flag.

Resources