@@ -382,18 +382,33 @@ internal object SimulationModel {
382382 }
383383
384384 private fun visitConstant (name : String , context : Context , root : Any? ): Result <Constant <* >>? {
385- val constant: Result <Constant <* >>? =
386- when (root) {
387- is Map <* , * > -> {
388- visitDependentVariable(name, context, root)
389- ?.mapCatching { it.getWith(context.constants) }
390- ?.onFailure {
391- logger.debug(" Evaluation failed at {}, context {}:\n {}" , root, context, it.message)
392- }?.onSuccess { context.registerConstant(name, root, it) }
393- ?.map { Constant (it) }
394- }
395- else -> null
385+ fun unsupportedConstantInstantiation (): Nothing = throw IllegalArgumentException (
386+ """
387+ Constant creation failed: '$name ' with value '$root '.
388+ Direct constant instantiation from YAML is not supported, please consult the Alchemist YAML spec at:
389+ > https://alchemistsimulator.github.io/reference/yaml/index.html#variable
390+ Likely workaround:
391+ ```yaml
392+ $name :
393+ formula: >
394+ $root
395+ ```
396+ """ .trimIndent(),
397+ )
398+ val constant: Result <Constant <* >>? = when (root) {
399+ is Number -> unsupportedConstantInstantiation()
400+ is String -> unsupportedConstantInstantiation()
401+ is Boolean -> unsupportedConstantInstantiation()
402+ is Map <* , * > -> {
403+ visitDependentVariable(name, context, root)
404+ ?.mapCatching { it.getWith(context.constants) }
405+ ?.onFailure {
406+ logger.debug(" Evaluation failed at {}, context {}:\n {}" , root, context, it.message)
407+ }?.onSuccess { context.registerConstant(name, root, it) }
408+ ?.map { Constant (it) }
396409 }
410+ else -> null
411+ }
397412 constant?.onSuccess {
398413 logger.debug(" Variable {}, evaluated from {} as constant, returned {}" , name, root, it.value)
399414 check(! context.constants.containsKey(name) || context.constants[name] == it.value) {
0 commit comments