-
Notifications
You must be signed in to change notification settings - Fork 14
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
Compilation fails with an unknown error
message
#119
Comments
Should be fix in 0.5.2.6 |
version 0.5.2.6 (Ckan) Hi ! Here is another one : use { MAINFRAME } from ksp::game
fn foo() -> Unit = {
const bar = MAINFRAME.available_processes
.map(fn(process) -> (name: string = process.name))
// const bar = MAINFRAME.available_processes
// .map(fn(process) -> (name: process.name)) // correct way to write it
} leads to
The mistake here is to define type of the record entry where it is already typed by the value inserted. However, the compiler have is very own way to says it :) Edit : add a case where the compiler is lost Here's an other one ;) use { Ship } from ship::ship
/// Entry Point
pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = {
if(false)
return Err("Vessel unable to carry out its mission \r\n")
// return Ok({})
}
Corrected by uncomment the Is assume it eventualy spit an |
Type annotations in "anoymous" records are not supported (yet?). As for this if-case: That was a bug, internally the |
version 0.5.2.6 (Ckan) Hi ! Let's say I have 3 files : use { ThrustSituation, ThrustSituationConst } from _gitreport::compilfail0::ship::constant
pub struct Ship(){}
impl Ship {
fn thrust(self, context: ThrustSituationConst = ThrustSituation.Max_Vac) -> float = 0.0
} _gitreport::compilfail0::ship::constant.to2 pub type ThrustSituationConst = int
pub const ThrustSituation: (Max_Vac: ThrustSituationConst, Max_Atm: ThrustSituationConst) = (
Max_Vac: 2**0,
Max_Atm: 2**1
) _gitreport::compilfail0::ui::monitor.to2 use { yield } from ksp::game
use { Ship } from _gitreport::compilfail0::ship::ship
pub fn main_flight() -> Result<Unit, string> = {
monitor(Ship())
}
pub fn monitor(ship: Ship) -> bool = {
const toto = ship.thrust() // to gitreport
return true
} I get this error message :
If I comment the
With other methods without default value, it work fines. But I suspect just it's not defaults values, but defaults values in Records which are faulty. |
Quick analysis: The problem is the default-value for the context parameter:
workaround would be to change it to
Under the hood it is again a nasty hen-egg problem I am still wrapping my head around |
Looks like I like chickens a little too much ;) |
It should work now in the 0.5.2.7 release |
version 0.5.2.7 (Ckan) Pokémon 'Gotta catch 'em all !' Thanks to a misstyping, got this one : _gitreport::compilfail.to2 // ko v0.5.2.7 issue #119
// ok v
use { Vessel } from ksp::vessel
use { current_time } from ksp::game
use { Direction } from ksp::math
pub struct Foobar(vessel: Vessel) {
normal: fn() -> Direction = fn() -> vessel.orbit.normal_plus(current_time).to_direction()
// normal: fn() -> Direction = fn() -> vessel.orbit.normal_plus(current_time()).to_direction()
radial: fn() -> Direction = fn() -> vessel.orbit.radial_plus(current_time()).to_direction()
antiradial: fn() -> Direction = fn() -> (-vessel.orbit.radial_plus(current_time())).to_direction()
} Which gives us a nice
Obvioulsy, the correct way to not get an error is the commented one. Have a nice day ! |
version 0.5.2.8 (Ckan) Hi ! Got this one : // ko v0.5.2.8 issue #119
// ok
use { Vessel } from ksp::vessel
use { Body } from ksp::orbit
pub type ApsisConst = int
pub const Apsis: (Periapsis: ApsisConst, Apoapsis: ApsisConst) = (
Periapsis: 0,
Apoapsis: 1
)
pub type ApsisModificationConst = float
pub const ApsisModification: (Raise: ApsisModificationConst, Decrease: ApsisModificationConst, Cheaper: ApsisModificationConst) = (
Raise: 0,
Decrease: 180,
Cheaper: -360
)
sync fn atmosphere_depth(body: Body) -> float = {
return if(body.has_atmosphere) body.atmosphere_depth else 0.0
}
pub fn circularize(vessel: Vessel, way: ApsisModificationConst = ApsisModification.Cheaper) -> Result<Unit, string> = {
const body = vessel.main_body
if(vessel.orbit.periapsis < atmosphere_depth(body) && (!vessel.orbit.apoapsis.defined))
return Err("Unable to circularize " + vessel.name)
if(vessel.orbit.periapsis < atmosphere_depth(body) && way == ApsisModification.Decrease)
return Err("Unable to circularize " + vessel.name + " at " + vessel.orbit.periapsis.to_fixed(0) + " because it's below " + vessel.main_body.name + "'s atmosphere.")
if((!vessel.orbit.apoapsis.defined) && way == ApsisModification.Raise)
return Err("Unable to circularize " + vessel.name + " at apoapsis because of hyperbolic orbit (escape " + vessel.main_body.name + "'s sphere of influence)")
if(way == ApsisModification.Raise) {
return foobar(vessel, Apsis.Periapsis, vessel.orbit.apoapsis.value)
} else if(way == ApsisModification.Decrease) {
return foobar(vessel, Apsis.Apoapsis, vessel.orbit.periapsis)
}
else {
return Ok({}) // TODO
}
}
fn foobar(vessel: Vessel, apsis: ApsisConst, altitude:float) -> Result<Unit, string> = {
//things
return Ok({})
} which gives us a nice
However, this pub fn circularize(vessel: Vessel, way: ApsisModificationConst = ApsisModification.Cheaper) -> Result<Unit, string> = {
const body = vessel.main_body
if(vessel.orbit.periapsis < atmosphere_depth(body) && (!vessel.orbit.apoapsis.defined))
return Err("Unable to circularize " + vessel.name)
if(vessel.orbit.periapsis < atmosphere_depth(body) && way == ApsisModification.Decrease)
return Err("Unable to circularize " + vessel.name + " at " + vessel.orbit.periapsis.to_fixed(0) + " because it's below " + vessel.main_body.name + "'s atmosphere.")
if((!vessel.orbit.apoapsis.defined) && way == ApsisModification.Raise)
return Err("Unable to circularize " + vessel.name + " at apoapsis because of hyperbolic orbit (escape " + vessel.main_body.name + "'s sphere of influence)")
if(way == ApsisModification.Raise)
return foobar(vessel, Apsis.Periapsis, vessel.orbit.apoapsis.value)
} is perfectly fine :
I should admit I'm pettry lost with this one. Edit : updated to the 0.5.3.0 Prerelease |
The compiler struggles to detect that the function ends after an
So instead of:
This should work:
or this:
|
Uh, Yes, now you mention it, I had catch numerous times where the compiler struggle with if/else form. Often, I had to transform some fn even(a: float) -> bool = {
if(a%2 == 0)
return true
else
return false
} in fn even(a: float) -> bool = {
if(a%2 == 0)
return true
return false
} because of some kind of
But as the message was clear and the correction was so easy I didn't really pay attention. |
and the original if-case in circularize should now work in 0.5.3.1 |
This issue is stale because it has been open for 60 days with no activity. |
This issue was closed because it has been inactive for 14 days since being marked as stale. |
version 0.5.2.5 (Ckan)
Hi, I made a mistake and wrote wrong code (how surprizing ! ;D)
The compiler obviously rage quit. However, the message is intriguing (surely, the linker get less token than expected).
Here the code :
gitreport::compilfail::ship::constant.to2
gitreport::compilfail::ship::stage.to2
gitreport::compilfail::console::missingimport.to2
Note than missingimport.to2 isn't in the same folder than the other two.
Here the error message :
while I usually get a nice "InvalidType Unable to lookup type Blablablaaa" or something similar.
The obvious solution is to not write wrong code (and uncomment the import in gitreport::compilfail::console::missingimport.to2 will fix that error), but I feel the nice message is also expected in the situation I've just describe.
Edit : typo
The text was updated successfully, but these errors were encountered: